From 69972820c809453061d46831bbdfd7de81772789 Mon Sep 17 00:00:00 2001 From: Denis Demchenko Date: Fri, 12 Apr 2019 21:04:58 +0300 Subject: [PATCH 1/5] Fix the bug with unset alias for a browser fix #313 --- src/parser.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/parser.js b/src/parser.js index 88706a8..f7ec7e9 100644 --- a/src/parser.js +++ b/src/parser.js @@ -402,12 +402,13 @@ class Parser { return undefined; } - isBrowser(browserName, loosely = false) { + isBrowser(browserName, includingAlias = false) { const defaultBrowserName = this.getBrowserName(); const possibleNames = [defaultBrowserName.toLowerCase()]; + const alias = Utils.getBrowserAlias(defaultBrowserName); - if (loosely) { - possibleNames.push(Utils.getBrowserAlias(defaultBrowserName).toLowerCase()); + if (includingAlias && typeof alias !== 'undefined') { + possibleNames.push(alias.toLowerCase()); } return possibleNames.indexOf(browserName.toLowerCase()) !== -1; From 4b658441ca028b93d7a42e429031accc33ee3dff Mon Sep 17 00:00:00 2001 From: Denis Demchenko Date: Fri, 12 Apr 2019 21:06:09 +0300 Subject: [PATCH 2/5] Add docs for `Parser#isBrowser` --- src/parser.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/parser.js b/src/parser.js index f7ec7e9..a91b404 100644 --- a/src/parser.js +++ b/src/parser.js @@ -402,6 +402,12 @@ class Parser { return undefined; } + /** + * Check if the browser name equals the passed string + * @param browserName The string to compare with the browser name + * @param [includingAlias=false] The flag showing whether alias will be included into comparison + * @returns {boolean} + */ isBrowser(browserName, includingAlias = false) { const defaultBrowserName = this.getBrowserName(); const possibleNames = [defaultBrowserName.toLowerCase()]; From 8212e48e02efdff34c609f47d52c692af715ea12 Mon Sep 17 00:00:00 2001 From: Denis Demchenko Date: Fri, 12 Apr 2019 21:35:17 +0300 Subject: [PATCH 3/5] Add tests for a browser without an alias --- test/unit/parser.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/unit/parser.js b/test/unit/parser.js index 10ec0d4..fbe9ae4 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -8,6 +8,9 @@ const parser = new Parser(UA, true); const EDGE_UA = 'Mozilla/5.0 (Linux; Android 8.0; Pixel XL Build/OPP3.170518.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.0 Mobile Safari/537.36 EdgA/41.1.35.1'; const edgeParser = new Parser(EDGE_UA, true); +const FOCUS_UA = 'Mozilla/5.0 (Linux; Android 7.1.1) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Focus/1.2.1 Chrome/59.0.3071.125'; +const focusParser = new Parser(FOCUS_UA, true); + test('constructor', (t) => { t.truthy(parser instanceof Parser); }); @@ -184,3 +187,8 @@ test('Parser.isBrowser should pass when loosely checking', (t) => { t.is(edgeParser.isBrowser('edge', true), true); t.is(edgeParser.isBrowser('Edge', true), true); }); + +test('Parser.isBrowser should pass for non-aliased browsers', (t) => { + t.is(focusParser.isBrowser('Focus', true), true); + t.is(focusParser.isBrowser('Focus', false), true); +}); From 328852aa0e79ff9825f06851c76cbd1e19cc7478 Mon Sep 17 00:00:00 2001 From: Denis Demchenko Date: Fri, 12 Apr 2019 21:43:09 +0300 Subject: [PATCH 4/5] Add an alias for Samsung Internet related to #313 --- src/constants.js | 1 + src/parser.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/constants.js b/src/constants.js index d0e084c..dfae9ee 100644 --- a/src/constants.js +++ b/src/constants.js @@ -25,6 +25,7 @@ const BROWSER_ALIASES_MAP = { QupZilla: 'qupzilla', Safari: 'safari', Sailfish: 'sailfish', + 'Samsung Internet for Android': 'samsung_internet', SeaMonkey: 'seamonkey', Sleipnir: 'sleipnir', Swing: 'swing', diff --git a/src/parser.js b/src/parser.js index a91b404..1470de8 100644 --- a/src/parser.js +++ b/src/parser.js @@ -343,11 +343,11 @@ class Parser { * * @example * const browser = new Bowser(UA); - * if (browser.check({chrome: '>118.01.1322' })) + * if (browser.satisfies({chrome: '>118.01.1322' })) * // or with os - * if (browser.check({windows: { chrome: '>118.01.1322' } })) + * if (browser.satisfies({windows: { chrome: '>118.01.1322' } })) * // or with platforms - * if (browser.check({desktop: { chrome: '>118.01.1322' } })) + * if (browser.satisfies({desktop: { chrome: '>118.01.1322' } })) */ satisfies(checkTree) { const platformsAndOSes = {}; From 51d8b0f3eab08aee3b07291531df9bc6d24db4ba Mon Sep 17 00:00:00 2001 From: Denis Demchenko Date: Fri, 12 Apr 2019 21:46:17 +0300 Subject: [PATCH 5/5] Bump version, write changelog --- CHANGELOG.md | 4 ++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a30be6..b141de1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Bowser Changelog +### 2.2.1 (April 12, 2019) +- [ADD] Add an alias for Samsung Internet +- [FIX] Fix browser name detection for browsers without an alias (#313) + ### 2.2.0 (April 7, 2019) - [ADD] Add short aliases for browser names (#295) - [FIX] Fix Yandex Browser version detection (#308) diff --git a/package-lock.json b/package-lock.json index fc5383e..f9cfa56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bowser", - "version": "2.2.0", + "version": "2.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9db9c71..8167cc0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bowser", - "version": "2.2.0", + "version": "2.2.1", "description": "Lightweight browser detector", "keywords": [ "browser",