Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing the version number throws an error if it contains letters #513

Open
ssp opened this issue May 17, 2022 · 0 comments
Open

Parsing the version number throws an error if it contains letters #513

ssp opened this issue May 17, 2022 · 0 comments

Comments

@ssp
Copy link

ssp commented May 17, 2022

Template to report about browser detection issue

We observed a user agent

Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 OPR/82.0.4227.58/VoplfMPIL3LW69FfgZ

which causes .satisfies to throw an error. E.g.

const browser = Bowser.getParser('Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 OPR/82.0.4227.58/VoplfMPIL3LW69FfgZ');
browser.satisfies({
    mobile: {
      opera: '>=60',
    },
    safari: '>=12',
    chrome: '>=88',
    android: '>=88',
    samsung_internet: '>=12',
    firefox: '>=90',
    edge: '>=90',
    opera: '>=80',
    ie: '>11',
  });

results in:

RangeError: Invalid array length
at ./node_modules/.pnpm/[email protected]/node_modules/bowser/es5.js:1:3125
at Array.map (<anonymous>)
at Function.e.map (./node_modules/.pnpm/[email protected]/node_modules/bowser/es5.js:1:3404)
at ./node_modules/.pnpm/[email protected]/node_modules/bowser/es5.js:1:3088
at Array.map (<anonymous>)
at Function.e.map (./node_modules/.pnpm/[email protected]/node_modules/bowser/es5.js:1:3404)
at Function.e.compareVersions (./node_modules/.pnpm/[email protected]/node_modules/bowser/es5.js:1:2993)
at e.t.compareVersion (./node_modules/.pnpm/[email protected]/node_modules/bowser/es5.js:1:11272)
at e.t.satisfies (./node_modules/.pnpm/[email protected]/node_modules/bowser/es5.js:1:10778)
at isBrowserValid (./src/lib/browserValidator.ts:10:36)
...

We can protect ourselves from this by adding a try catch, but my expectation was that bowser does not expose problems like this to the caller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant