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

Inaccurate Typescript types for getBrowserVersion #492

Open
randak opened this issue Sep 20, 2021 · 0 comments
Open

Inaccurate Typescript types for getBrowserVersion #492

randak opened this issue Sep 20, 2021 · 0 comments

Comments

@randak
Copy link

randak commented Sep 20, 2021

https://github.com/lancedikson/bowser/blob/f09411489ced05811c91cc6670a8e4ca9cbe39a7/index.d.ts#L57

The Typescript types for getBrowserVersion state that it always returns a string. However, if the version string cannot be parsed from the browser's user agent string, the code never sets browser.version, causing it to be undefined in some cases.

Example:
https://github.com/lancedikson/bowser/blob/f09411489ced05811c91cc6670a8e4ca9cbe39a7/src/parser-browsers.js#L40-L42

This caused a runtime error in our application because we assumed the function would always return a string, but it did not. These types are misleading and should be corrected.

You can reproduce this issue with the following mangled user agent string: Mozilla/5.0 (Linux; U; Android 4.0.2; en-us; Galaxy Nexus Build/ICL53F) AppleWebKit/534.30 (KHTML, like Gecko) Version 4.0 Mobile Safari/534.30. This is a contrived example (Version/4.0 was replaced with Version 4.0) but it demonstrates that the library sometimes returns undefined. Since user agent strings are effectively user input, this issue can (and does) happen in the wild.

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