Skip to content

Crash for some user-agents #10

Closed
Closed

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/

Activity

  1. mariotsi commented on Dec 6, 2017

    @mariotsi
    Member

    Thanks for the issue. I'll try to investigate this.

  2. mariotsi commented on Dec 6, 2017

    @mariotsi
    Member

    Found the problem. Thanks for pointing it out. I'll fix asap

  3. mariotsi commented on Dec 7, 2017

    @mariotsi
    Member

    Version 0.2.5 is out, fixes this issue and contains updates for the database and the detection system (thanks @NielsLeenheer ).

    @stouf thanks for reporting this issue and for using this library.

    Enjoy!

  4. stouf commented on Dec 7, 2017

    @stouf
    Author

    @mariotsi Thanks a lot for taking such quick actions, much appreciated :)

  5. added a commit that references this issue on Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions