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

refined safari webapp or cna check #161

Closed
wants to merge 1 commit into from

Conversation

sallustfire
Copy link

I needed to be able to narrow down if requests are coming in from Apple's captive network assistant (CNA). It turns out that these UA strings are identical to the fullscreen webapp mode. I changed the method name to reflect that and attempted to make a check that is resistant to new browsers or changes in browser names. The only defining characteristic here is that it has AppleWebKit without Safari, but many UA strings satisfy this requirement and simply add additional non-Safari items. I noticed that the existing method returned incorrect results against some of the UA string in the test cases, so I updated the tests and believe I have corrected this.

def safari_webapp_mode_or_cna?
tokens = ua.scan(/(\w+)(?=\/[\d\.]+)/).flatten
tokens.include?('Mozilla') && tokens.include?('AppleWebKit') &&
(tokens.size == 2 || (tokens.size == 3 && tokens.include?('Mobile')))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

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

Successfully merging this pull request may close these issues.

None yet

3 participants