Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 430f0b3

Browse files
authoredApr 16, 2018
Merge pull request #9 from woothee/add-yandexbrowser
Add yandexbrowser
2 parents b61e9e4 + b51ed6c commit 430f0b3

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed
 

‎src/dataset.rs

+10
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ lazy_static! {
9696
vendor: "OS vendor",
9797
version: "",
9898
});
99+
dataset.insert("YaBrowser",
100+
WootheeResult {
101+
name: "Yandex Browser",
102+
browser_type: "browser",
103+
category: "",
104+
os: "",
105+
os_version: "".to_string(),
106+
vendor: "Yandex",
107+
version: "",
108+
});
99109
dataset.insert("Win",
100110
WootheeResult {
101111
name: "Windows UNKNOWN Ver",

‎src/parser.rs

+26
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ lazy_static! {
5050
static ref RX_PEAR: Regex = Regex::new(r"(?:PEAR HTTP_Request|HTTP_Request)(?: class|2)").unwrap();
5151
static ref RX_MAYBE_CRAWLER_OTHER: Regex = Regex::new(r"(?:Rome Client |UnwindFetchor/|ia_archiver |Summify |PostRank/)").unwrap();
5252
static ref RE_SLEIPNIR_VERSION: Regex = Regex::new(r"Sleipnir/([.0-9]+)").unwrap();
53+
static ref RX_YABROWSER_VERSION: Regex = Regex::new(r"YaBrowser/(\d+\.\d+\.\d+\.\d+)").unwrap();
5354
}
5455

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

229+
if self.challenge_yandexbrowser(agent, result) {
230+
return true;
231+
}
232+
228233
if self.challenge_safari_chrome(agent, result) {
229234
return true;
230235
}
@@ -535,6 +540,27 @@ impl Parser {
535540
true
536541
}
537542

543+
fn challenge_yandexbrowser<'a>(&self, agent: &'a str, result: &mut WootheeResult<'a>) -> bool {
544+
if !agent.contains("YaBrowser/") {
545+
return false;
546+
}
547+
548+
match RX_YABROWSER_VERSION.captures(agent) {
549+
Some(caps) => {
550+
result.version = caps.get(1).unwrap().as_str();
551+
}
552+
None => {
553+
return false;
554+
}
555+
}
556+
557+
if !self.populate_dataset(result, "YaBrowser") {
558+
return false;
559+
}
560+
561+
true
562+
}
563+
538564
fn challenge_safari_chrome<'a>(&self, agent: &'a str, result: &mut WootheeResult<'a>) -> bool {
539565
if agent.contains("Chrome") && agent.contains("wv") {
540566
return false;

‎tests/pc_misc.rs

+10
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,15 @@ mod tests {
200200
assert_eq!(result.version, "33.0.1750.152");
201201
}
202202
}
203+
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"#) {
204+
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""#),
205+
Some(result) => {
206+
assert_eq!(result.category, "pc");
207+
assert_eq!(result.name, "Yandex Browser");
208+
assert_eq!(result.os, "Linux");
209+
assert_eq!(result.os_version, "UNKNOWN".to_string());
210+
assert_eq!(result.version, "17.11.1.1087");
211+
}
212+
}
203213
}
204214
}

‎tests/pc_windows.rs

+10
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,15 @@ mod tests {
268268
assert_eq!(result.version, "UNKNOWN");
269269
}
270270
}
271+
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"#) {
272+
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""#),
273+
Some(result) => {
274+
assert_eq!(result.category, "pc");
275+
assert_eq!(result.name, "Yandex Browser");
276+
assert_eq!(result.os, "Windows 7");
277+
assert_eq!(result.os_version, "NT 6.1".to_string());
278+
assert_eq!(result.version, "18.1.1.839");
279+
}
280+
}
271281
}
272282
}

0 commit comments

Comments
 (0)
Please sign in to comment.