Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add yandexbrowser #9

Merged
merged 3 commits into from
Apr 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/dataset.rs
Original file line number Diff line number Diff line change
@@ -96,6 +96,16 @@ lazy_static! {
vendor: "OS vendor",
version: "",
});
dataset.insert("YaBrowser",
WootheeResult {
name: "Yandex Browser",
browser_type: "browser",
category: "",
os: "",
os_version: "".to_string(),
vendor: "Yandex",
version: "",
});
dataset.insert("Win",
WootheeResult {
name: "Windows UNKNOWN Ver",
26 changes: 26 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ lazy_static! {
static ref RX_PEAR: Regex = Regex::new(r"(?:PEAR HTTP_Request|HTTP_Request)(?: class|2)").unwrap();
static ref RX_MAYBE_CRAWLER_OTHER: Regex = Regex::new(r"(?:Rome Client |UnwindFetchor/|ia_archiver |Summify |PostRank/)").unwrap();
static ref RE_SLEIPNIR_VERSION: Regex = Regex::new(r"Sleipnir/([.0-9]+)").unwrap();
static ref RX_YABROWSER_VERSION: Regex = Regex::new(r"YaBrowser/(\d+\.\d+\.\d+\.\d+)").unwrap();
}

#[derive(Debug, Default)]
@@ -225,6 +226,10 @@ impl Parser {
return true;
}

if self.challenge_yandexbrowser(agent, result) {
return true;
}

if self.challenge_safari_chrome(agent, result) {
return true;
}
@@ -535,6 +540,27 @@ impl Parser {
true
}

fn challenge_yandexbrowser<'a>(&self, agent: &'a str, result: &mut WootheeResult<'a>) -> bool {
if !agent.contains("YaBrowser/") {
return false;
}

match RX_YABROWSER_VERSION.captures(agent) {
Some(caps) => {
result.version = caps.get(1).unwrap().as_str();
}
None => {
return false;
}
}

if !self.populate_dataset(result, "YaBrowser") {
return false;
}

true
}

fn challenge_safari_chrome<'a>(&self, agent: &'a str, result: &mut WootheeResult<'a>) -> bool {
if agent.contains("Chrome") && agent.contains("wv") {
return false;
10 changes: 10 additions & 0 deletions tests/pc_misc.rs
Original file line number Diff line number Diff line change
@@ -200,5 +200,15 @@ mod tests {
assert_eq!(result.version, "33.0.1750.152");
}
}
match parser.parse(r#"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 YaBrowser/17.11.1.1087 (beta) Yowser/2.5 Safari/537.36"#) {
None => panic!(r#"invalid parse. "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 YaBrowser/17.11.1.1087 (beta) Yowser/2.5 Safari/537.36""#),
Some(result) => {
assert_eq!(result.category, "pc");
assert_eq!(result.name, "Yandex Browser");
assert_eq!(result.os, "Linux");
assert_eq!(result.os_version, "UNKNOWN".to_string());
assert_eq!(result.version, "17.11.1.1087");
}
}
}
}
10 changes: 10 additions & 0 deletions tests/pc_windows.rs
Original file line number Diff line number Diff line change
@@ -268,5 +268,15 @@ mod tests {
assert_eq!(result.version, "UNKNOWN");
}
}
match parser.parse(r#"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 YaBrowser/18.1.1.839 Yowser/2.5 Safari/537.36"#) {
None => panic!(r#"invalid parse. "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 YaBrowser/18.1.1.839 Yowser/2.5 Safari/537.36""#),
Some(result) => {
assert_eq!(result.category, "pc");
assert_eq!(result.name, "Yandex Browser");
assert_eq!(result.os, "Windows 7");
assert_eq!(result.os_version, "NT 6.1".to_string());
assert_eq!(result.version, "18.1.1.839");
}
}
}
}