1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00

Fix the issue with undefined browser version string

fixes #243
This commit is contained in:
Denis Demchenko 2018-09-09 15:02:29 +03:00
parent 19af6a8f2e
commit ace0ce17ea
3 changed files with 32 additions and 4 deletions

View File

@ -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) {

View File

@ -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"

View File

@ -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);