From 72b59a9208d0dc79f1d9fdc26bfd7c9b81a0e6ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Leis?= Date: Wed, 17 Jul 2019 12:54:43 +0200 Subject: [PATCH 1/4] Add Android Pie to version names --- src/utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 171dfae..04018bb 100644 --- a/src/utils.js +++ b/src/utils.js @@ -69,7 +69,7 @@ export default class Utils { * 6.x - Marshmallow * 7.x - Nougat * 8.x - Oreo - * 9.x - ? + * 9.x - Pie * * @example * getAndroidVersionName("7.0") // 'Nougat' @@ -94,6 +94,7 @@ export default class Utils { if (v[0] === 6) return 'Marshmallow'; if (v[0] === 7) return 'Nougat'; if (v[0] === 8) return 'Oreo'; + if (v[0] === 9) return 'Pie'; return undefined; } From b298e8d866750b7ce2806c29ceead873ddcedc1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Leis?= Date: Wed, 17 Jul 2019 13:14:23 +0200 Subject: [PATCH 2/4] Add detection of macOS version names --- src/parser-os.js | 8 +++++- src/utils.js | 38 ++++++++++++++++++++++++++++ test/acceptance/useragentstrings.yml | 31 +++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/parser-os.js b/src/parser-os.js index 939aa34..a66a118 100644 --- a/src/parser-os.js +++ b/src/parser-os.js @@ -46,10 +46,16 @@ export default [ test: [/macintosh/i], describe(ua) { const version = Utils.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua).replace(/[_\s]/g, '.'); - return { + const versionName = Utils.getMacOSVersionName(version); + + const os = { name: OS_MAP.MacOS, version, }; + if (versionName) { + os.versionName = versionName; + } + return os; }, }, diff --git a/src/utils.js b/src/utils.js index 04018bb..2ce7cb6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -53,6 +53,44 @@ export default class Utils { } } + /** + * Get macOS version name + * 10.5 - Leopard + * 10.6 - Snow Leopard + * 10.7 - Lion + * 10.8 - Mountain Lion + * 10.9 - Mavericks + * 10.10 - Yosemite + * 10.11 - El Capitan + * 10.12 - Sierra + * 10.13 - High Sierra + * 10.14 - Mojave + * 10.15 - Catalina + * + * @example + * getMacOSVersionName("10.14") // 'Mojave' + * + * @param {string} version + * @return {string} versionName + */ + static getMacOSVersionName(version) { + const v = version.split('.').splice(0, 2).map(s => parseInt(s, 10) || 0); + v.push(0); + if (v[0] !== 10) return undefined; + if (v[1] === 5) return 'Leopard'; + if (v[1] === 6) return 'Snow Leopard'; + if (v[1] === 7) return 'Lion'; + if (v[1] === 8) return 'Mountain Lion'; + if (v[1] === 9) return 'Mavericks'; + if (v[1] === 10) return 'Yosemite'; + if (v[1] === 11) return 'El Capitan'; + if (v[1] === 12) return 'Sierra'; + if (v[1] === 13) return 'High Sierra'; + if (v[1] === 14) return 'Mojave'; + if (v[1] === 15) return 'Catalina'; + return undefined; + } + /** * Get Android version name * 1.5 - Cupcake diff --git a/test/acceptance/useragentstrings.yml b/test/acceptance/useragentstrings.yml index 713d577..474ba9a 100644 --- a/test/acceptance/useragentstrings.yml +++ b/test/acceptance/useragentstrings.yml @@ -216,6 +216,7 @@ os: name: "macOS" version: "10.6.7" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -378,6 +379,7 @@ os: name: "macOS" version: "10.6.3" + versionName: "Snow Leopard" platform: type: "tablet" vendor: "Amazon" @@ -539,6 +541,7 @@ os: name: "macOS" version: "10.6.7" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -665,6 +668,7 @@ os: name: "macOS" version: "10.10.3" + versionName: "Yosemite" platform: type: "desktop" vendor: "Apple" @@ -711,6 +715,7 @@ os: name: "macOS" version: "10.6.8" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -726,6 +731,7 @@ os: name: "macOS" version: "10.6.7" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -784,6 +790,7 @@ os: name: "macOS" version: "10.6.1" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -799,6 +806,7 @@ os: name: "macOS" version: "10.5.7" + versionName: "Leopard" platform: type: "desktop" vendor: "Apple" @@ -877,6 +885,7 @@ os: name: "macOS" version: "10.5.2" + versionName: "Leopard" platform: type: "mobile" vendor: "Apple" @@ -1540,6 +1549,7 @@ os: name: "macOS" version: "10.8" + versionName: "Mountain Lion" platform: type: "desktop" vendor: "Apple" @@ -1652,6 +1662,7 @@ os: name: "macOS" version: "10.6" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -1717,6 +1728,22 @@ engine: name: "WebKit" version: "601.1.46" + - + ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Firefox/68.0" + spec: + browser: + name: "Firefox" + version: "68.0" + os: + name: "macOS" + version: "10.14" + versionName: "Mojave" + platform: + type: "desktop" + vendor: "Apple" + engine: + name: "Gecko" + version: "20100101" SeaMonkey: - ua: "Mozilla/5.0 (Windows NT 5.2; rv:10.0.1) Gecko/20100101 Firefox/10.0.1 SeaMonkey/2.7.1" @@ -1742,6 +1769,7 @@ os: name: "macOS" version: "10.5" + versionName: "Leopard" platform: type: "desktop" vendor: "Apple" @@ -2252,6 +2280,7 @@ os: name: "macOS" version: "10.11.1" + versionName: "El Capitan" platform: type: "desktop" vendor: "Apple" @@ -2290,6 +2319,7 @@ os: name: "macOS" version: "10.6.8" + versionName: "Snow Leopard" platform: type: "desktop" vendor: "Apple" @@ -2614,6 +2644,7 @@ os: name: "macOS" version: "10.12.6" + versionName: "Sierra" platform: type: "desktop" vendor: "Apple" From b2b36e6adbc52ebf2ff56a5b533d4a89f794dac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Leis?= Date: Wed, 17 Jul 2019 14:13:17 +0200 Subject: [PATCH 3/4] Add unit test for OS version names --- test/unit/utils.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/unit/utils.js b/test/unit/utils.js index ecbf85f..e4490db 100644 --- a/test/unit/utils.js +++ b/test/unit/utils.js @@ -3,6 +3,8 @@ import { getBrowserAlias, getFirstMatch, getWindowsVersionName, + getMacOSVersionName, + getAndroidVersionName, compareVersions, } from '../../src/utils'; @@ -16,6 +18,17 @@ test('getWindowsVersionName', (t) => { t.is(getWindowsVersionName('XXX'), void 0); }); +test('getMacOSVersionName', (t) => { + t.is(getMacOSVersionName('10.14.5'), 'Mojave'); + t.is(getMacOSVersionName('XXX'), void 0); +}); + +test('getAndroidVersionName', (t) => { + t.is(getAndroidVersionName('8.0'), 'Oreo'); + t.is(getAndroidVersionName('9'), 'Pie'); + t.is(getWindowsVersionName('XXX'), void 0); +}); + test('compareVersions', (t) => { const comparisionsTasks = [ ['9.0', '10', -1], From 496136fd83cd397aeb2f6edc5f41af660ab32b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Leis?= Date: Wed, 17 Jul 2019 17:33:48 +0200 Subject: [PATCH 4/4] Fixes, refactor, new test cases --- src/utils.js | 26 ++++++------ test/acceptance/useragentstrings.yml | 62 ++++++++++++++++++++++++++++ test/unit/utils.js | 5 ++- 3 files changed, 80 insertions(+), 13 deletions(-) diff --git a/src/utils.js b/src/utils.js index 2ce7cb6..7e36f8f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -77,18 +77,20 @@ export default class Utils { const v = version.split('.').splice(0, 2).map(s => parseInt(s, 10) || 0); v.push(0); if (v[0] !== 10) return undefined; - if (v[1] === 5) return 'Leopard'; - if (v[1] === 6) return 'Snow Leopard'; - if (v[1] === 7) return 'Lion'; - if (v[1] === 8) return 'Mountain Lion'; - if (v[1] === 9) return 'Mavericks'; - if (v[1] === 10) return 'Yosemite'; - if (v[1] === 11) return 'El Capitan'; - if (v[1] === 12) return 'Sierra'; - if (v[1] === 13) return 'High Sierra'; - if (v[1] === 14) return 'Mojave'; - if (v[1] === 15) return 'Catalina'; - return undefined; + switch (v[1]) { + case 5: return 'Leopard'; + case 6: return 'Snow Leopard'; + case 7: return 'Lion'; + case 8: return 'Mountain Lion'; + case 9: return 'Mavericks'; + case 10: return 'Yosemite'; + case 11: return 'El Capitan'; + case 12: return 'Sierra'; + case 13: return 'High Sierra'; + case 14: return 'Mojave'; + case 15: return 'Catalina'; + default: return undefined; + } } /** diff --git a/test/acceptance/useragentstrings.yml b/test/acceptance/useragentstrings.yml index 474ba9a..403275a 100644 --- a/test/acceptance/useragentstrings.yml +++ b/test/acceptance/useragentstrings.yml @@ -207,6 +207,21 @@ type: "desktop" engine: name: "Blink" + - + ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" + spec: + browser: + name: "Chrome" + version: "49.0.2623.112" + os: + name: "macOS" + version: "10.7.5" + versionName: "Lion" + platform: + type: "desktop" + vendor: "Apple" + engine: + name: "Blink" - ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.57 Safari/534.24" spec: @@ -797,6 +812,22 @@ engine: name: "WebKit" version: "531.21.10" + - + ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A" + spec: + browser: + name: "Safari" + version: "7.0.3" + os: + name: "macOS" + version: "10.9.3" + versionName: "Mavericks" + platform: + type: "desktop" + vendor: "Apple" + engine: + name: "WebKit" + version: "537.75.14" - ua: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; de-de) AppleWebKit/525.28.3 (KHTML, like Gecko) Version/3.2.3 Safari/525.28.3" spec: @@ -876,6 +907,22 @@ engine: name: "WebKit" version: "532.9" + - + ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13) AppleWebKit/604.1.31 (KHTML, like Gecko) Version/11.0 Safari/604.1.31" + spec: + browser: + name: "Safari" + version: "11.0" + os: + name: "macOS" + version: "10.13" + versionName: "High Sierra" + platform: + type: "desktop" + vendor: "Apple" + engine: + name: "WebKit" + version: "604.1.31" - ua: "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_2; en-gb) AppleWebKit/526+ (KHTML, like Gecko) Version/3.1 iPhone" spec: @@ -2098,6 +2145,21 @@ engine: name: "WebKit" version: "533.1" + - + ua: "Mozilla/5.0 (Linux; U; Android 2.2; en-us; GT-I5800 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1" + spec: + browser: + name: "Android Browser" + version: "4.0" + os: + name: "Android" + version: "2.2" + versionName: "Froyo" + platform: + type: "mobile" + engine: + name: "WebKit" + version: "533.1" - ua: "Mozilla/5.0 (Linux; U; Android 1.6; ar-us; SonyEricssonX10i Build/R2BA026) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1" spec: diff --git a/test/unit/utils.js b/test/unit/utils.js index e4490db..b41843e 100644 --- a/test/unit/utils.js +++ b/test/unit/utils.js @@ -20,13 +20,16 @@ test('getWindowsVersionName', (t) => { test('getMacOSVersionName', (t) => { t.is(getMacOSVersionName('10.14.5'), 'Mojave'); + t.is(getMacOSVersionName('10.15'), 'Catalina'); + t.is(getMacOSVersionName('10.999999'), void 0); t.is(getMacOSVersionName('XXX'), void 0); }); test('getAndroidVersionName', (t) => { + t.is(getAndroidVersionName('1.0'), void 0); t.is(getAndroidVersionName('8.0'), 'Oreo'); t.is(getAndroidVersionName('9'), 'Pie'); - t.is(getWindowsVersionName('XXX'), void 0); + t.is(getAndroidVersionName('XXX'), void 0); }); test('compareVersions', (t) => {