From 6821276669e299b6d23a595fb60f386569955f09 Mon Sep 17 00:00:00 2001 From: Faisal Salman Date: Sat, 18 Mar 2023 10:41:54 +0700 Subject: [PATCH] Fix #218 #491 #517 #518 - introduce breaking changes: "Mac OS" => "macOS", "Chromium OS" => "Chrome OS" --- src/ua-parser.js | 10 +++------- test/os-test.json | 12 ++++++------ test/test.js | 7 ++++--- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/ua-parser.js b/src/ua-parser.js index 42ec24f..3f70353 100755 --- a/src/ua-parser.js +++ b/src/ua-parser.js @@ -84,8 +84,6 @@ OPERA = 'Opera', FACEBOOK = 'Facebook', - CHROMIUM_OS = 'Chromium OS', - MAC_OS = 'Mac OS', WINDOWS = 'Windows'; var NAVIGATOR = (typeof window !== UNDEF_TYPE && window.navigator) ? @@ -783,7 +781,7 @@ ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [ /(mac os x) ?([\w\. ]*)/i, /(macintosh|mac_powerpc\b)(?!.+haiku)/i // Mac OS - ], [[NAME, MAC_OS], [VERSION, /_/g, '.']], [ + ], [[NAME, 'macOS'], [VERSION, /_/g, '.']], [ // Mobile OSes /droid ([\w\.]+)\b.+(android[- ]x86|harmonyos)/i // Android-x86/HarmonyOS @@ -809,7 +807,7 @@ /crkey\/([\d\.]+)/i // Google Chromecast ], [VERSION, [NAME, CHROME+'cast']], [ /(cros) [\w]+(?:\)| ([\w\.]+)\b)/i // Chromium OS - ], [[NAME, CHROMIUM_OS], VERSION],[ + ], [[NAME, "Chrome OS"], VERSION],[ // Smart TVs /panasonic;(viera)/i, // Panasonic Viera @@ -1110,9 +1108,7 @@ ]); this.parse(); if (!this.get(NAME) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[PLATFORM] && NAVIGATOR_UADATA[PLATFORM] != 'Unknown') { - this.set(NAME, NAVIGATOR_UADATA[PLATFORM] - .replace(/chrome os/i, CHROMIUM_OS) - .replace(/macos/i, MAC_OS)); // backward compatibility + this.set(NAME, NAVIGATOR_UADATA[PLATFORM]); } } UAParserOS.prototype = new UAParserItem(); diff --git a/test/os-test.json b/test/os-test.json index d97c7ff..f720a1a 100644 --- a/test/os-test.json +++ b/test/os-test.json @@ -670,7 +670,7 @@ "ua" : "Mozilla/5.0 (X11; CrOS x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.0.0 Safari/537.36", "expect" : { - "name" : "Chromium OS", + "name" : "Chrome OS", "version" : "undefined" } }, @@ -679,7 +679,7 @@ "ua" : "Mozilla/5.0 (X11; CrOS x86_64 10575.58.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36", "expect" : { - "name" : "Chromium OS", + "name" : "Chrome OS", "version" : "10575.58.0" } }, @@ -796,7 +796,7 @@ "ua" : "Mozilla/4.0 (compatible; MSIE 5.0b1; Mac_PowerPC)", "expect" : { - "name" : "Mac OS", + "name" : "macOS", "version" : "undefined" } }, @@ -805,7 +805,7 @@ "ua" : "Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0", "expect" : { - "name" : "Mac OS", + "name" : "macOS", "version" : "x.y" } }, @@ -814,7 +814,7 @@ "ua" : "Mozilla/5.0 (Macintosh; PPC Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0", "expect" : { - "name" : "Mac OS", + "name" : "macOS", "version" : "x.y" } }, @@ -823,7 +823,7 @@ "ua" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36", "expect" : { - "name" : "Mac OS", + "name" : "macOS", "version" : "10.6.8" } }, diff --git a/test/test.js b/test/test.js index aab97ad..39e948e 100644 --- a/test/test.js +++ b/test/test.js @@ -229,11 +229,12 @@ describe('is() utility method', function () { it('Should get result after reassignment', function () { uap.setUA("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36"); - assert.strictEqual(uap.getOS().name, "Mac OS"); + assert.strictEqual(uap.getOS().name, "macOS"); assert.strictEqual(uap.getOS().is("Mac OS"), true); - assert.strictEqual(uap.getOS().is("M ac"), false); assert.strictEqual(uap.getOS().is("macOS"), true); assert.strictEqual(uap.getOS().is("mac OS"), true); + + assert.strictEqual(uap.getOS().is("M ac"), false); assert.strictEqual(uap.getOS().is("M a c "), false); assert.strictEqual(uap.getOS().is("Mac OS OS"), false); assert.strictEqual(uap.getOS().is("Mac OS X"), false); @@ -542,7 +543,7 @@ describe('Map UA-CH JS', () => { assert.strictEqual(result_without_ch.browser.name, undefined); uap.setUA("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36"); - assert.strictEqual(uap.getOS().name, "Mac OS"); + assert.strictEqual(uap.getOS().name, "macOS"); // TODO : create full tests });