Skip to content

Commit

Permalink
feat: update to 1.5.1 of @financial-times/useragent_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeChampion committed Mar 19, 2020
1 parent 52c5187 commit e2859cc
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 61 deletions.
4 changes: 1 addition & 3 deletions compilers/fastly.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ for (const [family, alias] of Object.entries(data.aliases)) {
}
file += `
set req.http.normalized_user_agent_family = "${replacement[0]}";
set req.http.normalized_user_agent_major_version = "${
replacement[1]
}";
set req.http.normalized_user_agent_major_version = "${replacement[1]}";
set req.http.normalized_user_agent_minor_version = "0";
}`;
}
Expand Down
1 change: 1 addition & 0 deletions data.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"iphone simulator": "ios_saf",
"mobile safari uiwebview": "ios_saf",
"mobile safari ui/wkwebview": "ios_saf",
"mobile safari/wkwebview": "ios_saf",

"samsung internet": "samsung_mob",

Expand Down
3 changes: 2 additions & 1 deletion fastly/vcl/main.vcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

include "normalise-user-agent.vcl";

sub vcl_recv {
Expand All @@ -6,7 +7,7 @@ sub vcl_recv {

sub vcl_error {
if (obj.status == 903) {
call normalise_user_agent_1_5_1;
call normalise_user_agent_1_6_3;
set obj.status = 200;
set obj.response = "OK";
set obj.http.Content-Type = "text/plain; charset=utf-8";
Expand Down
110 changes: 108 additions & 2 deletions lib/normalise-user-agent.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,111 @@ sub useragent_parser {
declare local var.Patch STRING;
set var.Patch = "";
if (!req.http.User-Agent) {
} else if (req.http.User-Agent ~ {"(iPod|iPod touch|iPhone|iPad);.*CPU.*OS[ +](\d+)_(\d+)(?:_(\d+)|).* like Gecko\) (?!Version\/[\d.]+)[A-Za-z]+\/[\d.]+"}) {
set var.Family = "Mobile Safari UI/WKWebView";
} else if (req.http.User-Agent ~ {"Opera/9\.80 \(.+(Opera Mini)/(\d+)(?:\.(\d+)|)(?:\.(\d+)|)"}) {
set var.Family = re.group.1;
set var.Major = re.group.2;
set var.Minor = re.group.3;
set var.Patch = re.group.4;
} else if (req.http.User-Agent ~ {"Opera/9\.80 \(.+(Opera Mini)/(\d+)(?:\.(\d+)|)"}) {
set var.Family = re.group.1;
set var.Major = re.group.2;
set var.Minor = re.group.3;
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/525\.18(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "3";
set var.Minor="1";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/528\.18(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "4";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/531\.21(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "4";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/532\.9(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "4";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/532\+"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "5";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/533\.17(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "5";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/534\.12(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "5";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/534\.46(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "5";
set var.Minor="1";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/536\.26(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "6";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/537\.51(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "7";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/600\.1(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "8";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/601\.1(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "9";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/601\.5(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "9";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/602\.1(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "10";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/602\.2(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "10";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/602\.3(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "10";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/602\.4(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "10";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/603\.1(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "10";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/603\.2(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "10";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/604\.1(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "11";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/604\.2(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "11";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/604\.3(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "11";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/604\.5(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "11";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/605\.1(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "11";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/606\.1(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "12";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/607\.1(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "12";
set var.Minor="1";
} else if (req.http.User-Agent ~ {"(iPod|iPhone|iPad).+AppleWebKit\/608\.2(?:\.\d+|)"}) {
set var.Family = "Mobile Safari/WKWebView";
set var.Major = "13";
} else if (req.http.User-Agent ~ {"(MQQBrowser/Mini)(?:(\d+)(?:\.(\d+)|)(?:\.(\d+)|)|)"}) {
set var.Family = "QQ Browser Mini";
set var.Major = re.group.2;
set var.Minor = re.group.3;
set var.Patch = re.group.4;
} else if (req.http.User-Agent ~ {"(MQQBrowser)(?:/(\d+)(?:\.(\d+)|)(?:\.(\d+)|)|)"}) {
set var.Family = "QQ Browser Mobile";
set var.Major = re.group.2;
set var.Minor = re.group.3;
set var.Patch = re.group.4;
} else if (req.http.User-Agent ~ {"(QQBrowser)(?:/(\d+)(?:\.(\d+)\.(\d+)(?:\.(\d+)|)|)|)"}) {
set var.Family = "QQ Browser";
set var.Major = re.group.2;
set var.Minor = re.group.3;
set var.Patch = re.group.4;
Expand Down Expand Up @@ -1418,6 +1521,9 @@ sub normalise_user_agent_1_6_3 {
set req.http.normalized_user_agent_family = "ios_saf";
}
if (req.http.normalized_user_agent_family == "mobile safari ui/wkwebview") {
set req.http.normalized_user_agent_family = "ios_saf";
}
if (req.http.normalized_user_agent_family == "mobile safari/wkwebview") {
set req.http.normalized_user_agent_family = "ios_saf";
}
if (req.http.normalized_user_agent_family == "samsung internet") {
Expand Down
23 changes: 15 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@financial-times/useragent_parser": "^1.2.1",
"@financial-times/useragent_parser": "^1.5.1",
"semver": "^7.1.1"
},
"devDependencies": {
Expand Down
21 changes: 10 additions & 11 deletions test/integration/normalise-user-agent-test-cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@
},
{
"input": "Mozilla/5.0 (iPod touch; CPU iPhone OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13F69",
"output": "ios_saf/9.3.0"
"output": "ios_saf/9.0.0"
},
{
"input": "Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257",
Expand Down Expand Up @@ -704,7 +704,7 @@
},
{
"input": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_6 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Whale/0.9.1.679 Mobile/15D100 Safari/604.5.6",
"output": "ios_saf/11.2.0"
"output": "ios_saf/11.0.0"
},
{
"input": "Mozilla/5.0 (Linux; Android 6.0.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Whale/0.9.5.0 Mobile Safari/537.36",
Expand Down Expand Up @@ -4532,17 +4532,16 @@
},
{
"input": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 Instagram 80.0.0.12.107",
"output": "ios_saf/12.1.0"
"output": "ios_saf/11.0.0"
},
{
"input": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/66.0.230776083 Mobile/15E148 Safari/605.1",
"output": "ios_saf/12.1.0"
"output": "ios_saf/11.0.0"
},
{
"input": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 YaBrowser/18.10.3.114.10 Mobile/15E148 Safari/605.1",
"output": "ios_saf/12.0.0"
"output": "ios_saf/11.0.0"
},

{
"input": "Mozilla/5.0 (Linux; Android 6.0; Lenovo K50a40 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.137 YaBrowser/17.4.1.352.00 Mobile Safari/537.36",
"output": "chrome/57.0.0"
Expand Down Expand Up @@ -4777,7 +4776,7 @@
},
{
"input": "Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_4 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) Outlook-iOS-Android/1.0 Mobile/13G35 Safari/601.1.46\")",
"output": "other/0.0.0"
"output": "ios_saf/9.0.0"
},
{
"input": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.21 Safari/537.36 MMS/1.0.2459.0",
Expand Down Expand Up @@ -4805,7 +4804,7 @@
},
{
"input": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Mobile/14D27 SznProhlizec/4.4i",
"output": "ios_saf/10.2.0"
"output": "ios_saf/10.0.0"
},
{
"input": "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/42.0 CoRom/36.0.1985.144 Chrome/36.0.1985.144 Safari/537.36",
Expand Down Expand Up @@ -4949,23 +4948,23 @@
},
{
"input": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Snapchat/10.44.1.1 (iPhone7,2; iOS 10.2.1; gzip)",
"output": "ios_saf/10.2.0"
"output": "ios_saf/10.0.0"
},
{
"input": "Mozilla/5.0 (Linux; Android 7.0; LG-TP260 Build/NRD90U; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/64.0.3282.137 Mobile Safari/537.36 Instagram 33.0.0.11.92 Android (24/7.0; 320dpi; 720x1193; LGE/lge; LG-TP260; lv517; lv517; en_US; 93117667)",
"output": "chrome/64.0.0"
},
{
"input": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_5 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Mobile/15D60 Instagram 33.0.0.11.96 (iPhone9,3; iOS 11_2_5; en_AU; en-AU; scale=2.00; gamut=wide; 750x1334)",
"output": "ios_saf/11.2.0"
"output": "ios_saf/11.0.0"
},
{
"input": "Mozilla/5.0 (Linux; Android 6.0; PLK-L01 Build/HONORPLK-L01) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Crosswalk/23.53.589.2 Mobile Safari/537.36 LibertyBrowser/1.5.3",
"output": "chrome/53.0.0"
},
{
"input": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_6 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Mobile/15D100 Flipboard/4.2.2",
"output": "ios_saf/11.2.0"
"output": "ios_saf/11.0.0"
},
{
"input": "Mozilla/5.0 (Linux; Android 7.0; SM-G610F Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/63.0.3239.111 Mobile Safari/537.36 Flipboard/4.1.9/4323,4.1.9.4323",
Expand Down

0 comments on commit e2859cc

Please sign in to comment.