device-detector
device-detector copied to clipboard
fix Android tablet detection in VERSION_TRUNCATION_MAJOR mode
Description:
Hello,
First, thanks a lot for this awesome library!
Because of privacy concerns, I'm using this library in VERSION_TRUNCATION_MAJOR
, and I noticed some issues when parsing some old Android 3 tablet user-agents. The device ends up empty instead of tablet
.
Looking at the code, it's because of the builtin version_compare
, for which, I'm not sure why, 3
is lower than 3.0
instead of being equals. I fixed the issue by using only major versions in version_compare
, instead of major + minor.
For the tests, I've just duplicated the existing ones, running with VERSION_TRUNCATION_MAJOR
instead of VERSION_TRUNCATION_NONE
. There's probably a better / faster solution, please tell me what you think.
Thanks a lot in advance!
Review
- [ ] Functional review done
- [ ] Potential edge cases thought about (behavior of the code with strange input, with strange internal state or possible interactions with other Matomo subsystems)
- [ ] Usability review done (is anything maybe unclear or think about anything that would cause people to reach out to support)
- [ ] Security review done
- [ ] Wording review done
- [ ] Code review done
- [ ] Tests were added if useful/possible
- [ ] Reviewed for breaking changes
- [ ] Developer changelog updated if needed
- [ ] Documentation added if needed
- [ ] Existing documentation updated if needed
It was a bit harder than expected, because the browser version is used in regexes to guess the browser engine, and, when truncated, it leads to different results.
I extracted the version truncation from the buildVersion
to a dedicated truncateVersion
and updated the code accordingly. This allows to use the full version to guess the engine, while propagating the truncated version.
Let me know what you think.
Thanks!