Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

TypeError: Cannot read property '1' of null at parse call #16

Closed
okv opened this issue Nov 26, 2012 · 2 comments
Closed

TypeError: Cannot read property '1' of null at parse call #16

okv opened this issue Nov 26, 2012 · 2 comments
Labels

Comments

@okv
Copy link

okv commented Nov 26, 2012

Hi, there!
I have following error when try to parse user agent:

TypeError: Cannot read property '1' of null
    at Object.parse (node_modules/platform/platform.js:783:54)

My user agent is "todotogo/6 (iPhone Simulator; iOS 6.0; Scale/1.00)".
This user agent is auto generated by AFNetworking (https://github.com/AFNetworking/AFNetworking) library.

It would be great if platform.parse method just return null or undefined if he can't parse browser name, version, etc.

@terinjokes
Copy link

If a check for layout is added to line 796

    // detect Chrome desktop mode
    else if (layout && name == 'Safari' && /Chrome/.exec(layout[1])) {

todotogo is detected as a generic Safari on iPhone.

{
  "version": null,
  "name": "Safari",
  "os": {
    "architecture": 32,
    "family": "iOS",
    "version": null
  },
  "description": "Safari on Apple iPhone Simulator",
  "layout": null,
  "manufacturer": "Apple",
  "prerelease": null,
  "product": "iPhone Simulator",
  "ua": "todotogo/6 (iPhone Simulator; iOS 6.0; Scale/1.00)"
} 

Not perfect, but far better than throwing an exception.

@renehamburger
Copy link

We are using the current version of Platform (1.0.0) -- though I just realised that that doesn't include the code update 3 months ago, probably because the version number wasn't increased -- to determine the CSP headers supported by the client's browser. In rare cases platform.js causes this exception on line 796 because layout is set to null in line 258.

We didn't log the user agent string that caused this issue but an unknown user agent should certainly not lead to a crash. @terinjokes suggestion would solve this particular crash but layout is assumed to be an array in other places too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

4 participants