browserslist-useragent-ruby icon indicating copy to clipboard operation
browserslist-useragent-ruby copied to clipboard

iOS Safari version detection

Open chilled-capybara opened this issue 3 years ago • 0 comments

This is potentially a bug, or some imprecision/ambiguity in one of the code comments.

There are two cases related to resolving the iOS version within resolver.rb

https://github.com/browserslist/browserslist-useragent-ruby/blob/f17624b1c678a34d67038efcb17394b0175317ae/lib/browserslist_useragent/resolver.rb#L20-L34

Case B explains;

Case B: The browser on iOS didn't report as safari, so we use the iOS version as a proxy to the browser version. This is based on the assumption that the underlying Safari Engine used will be atleast equal to the iOS version it's running on.

However the condition used for this is simply

if agent.os.family == 'iOS'

As such, whether the browser identifies as Safari or not, the version number is set to the os version; making Case A redundant,

The comment would seem to suggest that there should be logic that is specifically checking for the absence of Safari;

if !agent.family.include?('Safari') && agent.os.family == 'iOS'

As background, this stems from the following real-world example;

ua = 'Mozilla/5.0 (iPad; CPU OS 12_5_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Mobile/15E148 Safari/604.1'
matcher = BrowserslistUseragent::Match.new(['ios_saf 12.2-12.5'], ua)
matcher.browser? && matcher.version?(allow_higher: true)

=> true

Where although it is Safari and iOS, it is replacing the browser version 12.1.2 with the os version 12.5.6 and returning a match. This potentially doesn't match the expectation based on the Case B comment.

chilled-capybara avatar Oct 19 '22 16:10 chilled-capybara