fix: correct Android Mobile browserVersion regex casing (null $browser_version on Android) - #609
Open
sarmah-rup wants to merge 1 commit into
Open
Conversation
The `versionRegexs` table entry for `Android Mobile` used a lowercase `/android\s.../` pattern with no `i` flag, so it never matched real user agent strings, which contain a capital `Android`. As a result `browserVersion` returned `null` for non-Chrome Android browsers, which in turn recorded a null `$browser_version`. Capitalize the pattern to `/Android\s.../` so it matches, consistent with every sibling reference in `browser()`, `os()`, and `device()`. Adds a regression test using a real Android 4.4.2 Samsung stock browser UA.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
versionRegexslookup insrc/utils.jsused a lowercase, unflagged pattern for theAndroid Mobilebrowser:Real Android user agent strings spell the token with a capital
Android(for exampleMozilla/5.0 (Linux; U; Android 4.4.2; ...)), so this regex never matched._.info.browserVersion()therefore returnednullfor these browsers. This changes the pattern to match the actual casing, consistent with every other place the same token is referenced:For reference, the sibling references already use the capitalized form:
browser()(_.includes(user_agent, 'Android')),os()(/Android/.test(a)), anddevice()(/Android/.test(user_agent)).Why (what I hit)
I was looking at my Android traffic in Mixpanel and noticed
$browser_versioncoming through as null for a slice of users. The affected ones were non-Chrome Android browsers (older stock/WebView user agents classified asAndroid Mobilerather thanChrome). Those get their version parsed by theAndroid Mobileregex, which never matched because of the lowercaseandroid, so every one recorded a null$browser_version. Chrome-on-Android was fine because it matches the separateChrome/...pattern.Test
Added a regression test in
tests/unit/utils.jsusing a real Android 4.4.2 Samsung stock browser user agent (classified asAndroid Mobile, not Chrome), asserting_.info.browser(ua, '', false)equalsAndroid Mobileand_.info.browserVersion(ua, '', false)equals4.4. Before the fix the version assertion fails withexpected null to equal 4.4. After the fix both pass.npm run unit-test-> 682 passing,npm run lintclean.