Skip to content

Crash for some user-agents #10

@stouf

Description

@stouf

I recently tried to use this library for parsing a bunch of user-agents but it crashed for the following one:

Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; O+ 8.36 Android Build/Oplus8.36_Oplus) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30

I used the following code, which worked just fine on many user-agents before crashing on the one I mentioned above:

'use strict';

const WhichBrowser = require('which-browser');

const useragent = 'Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; O+ 8.36 Android Build/Oplus8.36_Oplus) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';

// It is using a hard-coded user agent here, but this is how I was successfully using the library with other
// user-agents
const info = new WhichBrowser(useragent, {
  cache: WhichBrowser.SIMPLE_CACHE,
  cacheExpires: 90
});

console.log('Done!');

Here is the error:

/home/user/test/which-browser/node_modules/which-browser/src/data/DeviceModels.js:200
                for (let m2 of Object.keys(list[v] || list[originalV])) {
                                      ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Function.identifyList (/home/user/test/which-browser/node_modules/which-browser/src/data/DeviceModels.js:200:39)
    at Function.identifyAndroid (/home/user/test/which-browser/node_modules/which-browser/src/data/DeviceModels.js:145:33)
    at Function.identify (/home/user/test/which-browser/node_modules/which-browser/src/data/DeviceModels.js:25:29)
    at Useragent.detectAndroid (/home/user/test/which-browser/node_modules/which-browser/src/Analyser/Header/Useragent/Os.js:325:35)
    at Useragent.detectOperatingSystem (/home/user/test/which-browser/node_modules/which-browser/src/Analyser/Header/Useragent/Os.js:20:22)
    at new Useragent (/home/user/test/which-browser/node_modules/which-browser/src/Analyser/Header/Useragent.js:13:30)
    at Analyser.analyseUserAgent (/home/user/test/which-browser/node_modules/which-browser/src/Analyser/Header.js:74:5)
    at Analyser.analyseHeaders (/home/user/test/which-browser/node_modules/which-browser/src/Analyser/Header.js:11:31)
    at Analyser.analyse (/home/user/test/which-browser/node_modules/which-browser/src/Analyser.js:45:27)

I also noticed something interesting: the user-agent mentioned above can be successfully parsed by https://whichbrowser.net/tryout/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions