regex date checking
This commit is contained in:
@@ -10,6 +10,7 @@ use error_chain::error_chain;
|
||||
use htmlentity::entity::{ICodedDataTrait, decode};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::vec;
|
||||
use regex::Regex;
|
||||
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
@@ -18,6 +19,12 @@ error_chain! {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_valid_date(s: &str) -> bool {
|
||||
// Regex: strict yyyy-mm-dd (no validation of real calendar dates, just format)
|
||||
let re = Regex::new(r"^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$").unwrap();
|
||||
re.is_match(s)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct XxdbxProvider {
|
||||
url: String,
|
||||
@@ -124,6 +131,8 @@ impl XxdbxProvider {
|
||||
search_type = "channels";
|
||||
} else if self.stars.read().unwrap().iter().map(|s|s.to_ascii_lowercase()).collect::<Vec<String>>().contains(&search_string.to_ascii_lowercase()) {
|
||||
search_type = "stars";
|
||||
} else if is_valid_date(&search_string){
|
||||
search_type = "dates";
|
||||
}
|
||||
|
||||
let video_url = format!(
|
||||
|
||||
Reference in New Issue
Block a user