bowser
bowser copied to clipboard
Inaccurate Typescript types for getBrowserVersion
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.