diff --git a/src/parser.js b/src/parser.js index 283f7df..54b38e2 100644 --- a/src/parser.js +++ b/src/parser.js @@ -399,6 +399,12 @@ class Parser { let comparableVersion = version; let isLoose = false; + const currentBrowserVersion = this.getBrowserVersion(); + + if (typeof currentBrowserVersion !== 'string') { + return void 0; + } + if (version[0] === '>') { expectedResult = 1; comparableVersion = version.substr(1); @@ -412,7 +418,7 @@ class Parser { comparableVersion = version.substr(1); } - return compareVersions(this.getBrowserVersion(), comparableVersion, isLoose) === expectedResult; + return compareVersions(currentBrowserVersion, comparableVersion, isLoose) === expectedResult; } isOS(osName) { diff --git a/test/acceptance/useragentstrings.yml b/test/acceptance/useragentstrings.yml index 1781c34..a874af3 100644 --- a/test/acceptance/useragentstrings.yml +++ b/test/acceptance/useragentstrings.yml @@ -984,6 +984,20 @@ engine: name: "WebKit" version: "601.1.46" + - ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15G77 [FBAN/FBIOS;FBDV/iPhone7,2;FBMD/iPhone;FBSN/iOS;FBSV/11.4.1;FBSS/2;FBCR/vfnl;FBID/phone;FBLC/nl_NL;FBOP/5;FBRV/0]" + spec: + browser: + name: "Safari" + os: + name: "iOS" + version: "11.4.1" + platform: + type: "mobile" + vendor: "Apple" + model: "iPhone" + engine: + name: "WebKit" + version: "605.1.15" Internet Explorer: - ua: "Mozilla/5.0 (Windows NT 6.3; Win64; x64; Trident/7.0; MAARJS; rv:11.0) like Gecko" diff --git a/test/unit/parser.js b/test/unit/parser.js index 5e37a0b..53abe4c 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -57,7 +57,7 @@ test('Skip parsing shouldn\'t parse', (t) => { t.deepEqual((new Parser(UA, true)).getResult(), {}); }); -test('Parser.check should make simple comparisons', (t) => { +test('Parser.satisfies should make simple comparisons', (t) => { // also covers Parser.compareVersion() method t.is(parser.satisfies({ opera: '>42' }), true); t.is(parser.satisfies({ opera: '<44' }), true); @@ -66,7 +66,7 @@ test('Parser.check should make simple comparisons', (t) => { t.is(parser.satisfies({ opera: '~43' }), true); }); -test('Parser.check should make complex comparison', (t) => { +test('Parser.satisfies should make complex comparison', (t) => { t.is(parser.satisfies({ macos: { safari: '>11', @@ -78,7 +78,7 @@ test('Parser.check should make complex comparison', (t) => { }), true); }); -test('Parser.check should respect platform and OS specific declarations', (t) => { +test('Parser.satisfies should respect platform and OS specific declarations', (t) => { t.is(parser.satisfies({ macos: { opera: '>45', @@ -114,6 +114,14 @@ test('Parser.check should respect platform and OS specific declarations', (t) => }), void 0); }); +test('Parser.satisfies for versionless UA strings', (t) => { + const _parser = new Parser('Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15G77 [FBAN/FBIOS;FBDV/iPhone7,2;FBMD/iPhone;FBSN/iOS;FBSV/11.4.1;FBSS/2;FBCR/vfnl;FBID/phone;FBLC/nl_NL;FBOP/5;FBRV/0]'); + + t.is(_parser.satisfies({ + safari: '>9', + }), void 0); +}); + test('Parser.is should pass', (t) => { t.is(parser.is('opera'), true); t.is(parser.is('desktop'), true);