Module: ShouldSendSameSiteNone
- Defined in:
- lib/should_send_same_site_none.rb,
lib/should_send_same_site_none/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
- .drops_unrecognized_same_site(user_agent) ⇒ Object
- .extract_regex_match(string_value, regex, offsetIndex) ⇒ Object
- .has_webkit_bug(user_agent) ⇒ Object
- .is_chromium_based(user_agent) ⇒ Object
- .is_chromium_version_at_least(major, user_agent) ⇒ Object
- .is_compatible(user_agent) ⇒ Object
- .is_ios_version(major, user_agent) ⇒ Object
- .is_mac_embedded_browser(user_agent) ⇒ Object
- .is_macosx_version(major, minor, user_agent) ⇒ Object
- .is_safari(user_agent) ⇒ Object
- .is_same_site_compatible(user_agent) ⇒ Object
- .is_uc_browser(user_agent) ⇒ Object
- .is_uc_browser_version_at_least(major, minor, build, user_agent) ⇒ Object
- .regex_contains(string_value, regex) ⇒ Object
Class Method Details
.drops_unrecognized_same_site(user_agent) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/should_send_same_site_none.rb', line 25 def self.drops_unrecognized_same_site(user_agent) return ( (is_chromium_based(user_agent) && is_chromium_version_at_least(51, user_agent) && !is_chromium_version_at_least(67, user_agent)) || (is_uc_browser(user_agent) && !is_uc_browser_version_at_least(12, 13, 2, user_agent)) ) end |
.extract_regex_match(string_value, regex, offsetIndex) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/should_send_same_site_none.rb', line 87 def self.extract_regex_match(string_value, regex, offsetIndex) matches = string_value.match(regex) unless string_value.nil? if (matches != nil && matches[offsetIndex] != nil) return matches[offsetIndex] end return nil end |
.has_webkit_bug(user_agent) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/should_send_same_site_none.rb', line 17 def self.has_webkit_bug(user_agent) return ( is_ios_version(12, user_agent) || (is_macosx_version(10, 14, user_agent) && (is_safari(user_agent) || (user_agent))) ) end |
.is_chromium_based(user_agent) ⇒ Object
55 56 57 58 |
# File 'lib/should_send_same_site_none.rb', line 55 def self.is_chromium_based(user_agent) regex = /Chrom(e|ium)/ regex_contains(user_agent, regex) end |
.is_chromium_version_at_least(major, user_agent) ⇒ Object
60 61 62 63 64 |
# File 'lib/should_send_same_site_none.rb', line 60 def self.is_chromium_version_at_least(major, user_agent) regex = /Chrom[^ \/]+\/(\d+)[\.\d]* / version = extract_regex_match(user_agent, regex, 1).to_i return version >= major end |
.is_compatible(user_agent) ⇒ Object
11 12 13 14 15 |
# File 'lib/should_send_same_site_none.rb', line 11 def self.is_compatible(user_agent) return ( has_webkit_bug(user_agent) || drops_unrecognized_same_site(user_agent) ) end |
.is_ios_version(major, user_agent) ⇒ Object
34 35 36 37 38 |
# File 'lib/should_send_same_site_none.rb', line 34 def self.is_ios_version(major, user_agent) regex = /\(iP.+; CPU .*OS (\d+)[_\d]*.*\) AppleWebKit\// # Extract digits from first capturing group. extract_regex_match(user_agent, regex, 1) == major.to_s end |
.is_mac_embedded_browser(user_agent) ⇒ Object
50 51 52 53 |
# File 'lib/should_send_same_site_none.rb', line 50 def self.(user_agent) regex = /^Mozilla\/[\.\d]+ \(Macintosh;.*Mac OS X [_\d]+\) AppleWebKit\/[\.\d]+ \(KHTML, like Gecko\)$/ regex_contains(user_agent, regex) end |
.is_macosx_version(major, minor, user_agent) ⇒ Object
40 41 42 43 |
# File 'lib/should_send_same_site_none.rb', line 40 def self.is_macosx_version(major, minor, user_agent) regex = /\(Macintosh;.*Mac OS X (\d+)_(\d+)[_\d]*.*\) AppleWebKit\// extract_regex_match(user_agent, regex, 1) == major.to_s && extract_regex_match(user_agent, regex, 2) == minor.to_s end |
.is_safari(user_agent) ⇒ Object
45 46 47 48 |
# File 'lib/should_send_same_site_none.rb', line 45 def self.is_safari(user_agent) safari_regex = /Version\/.* Safari\// user_agent.match(safari_regex) != nil && !is_chromium_based(user_agent) end |
.is_same_site_compatible(user_agent) ⇒ Object
5 6 7 |
# File 'lib/should_send_same_site_none.rb', line 5 def self.is_same_site_compatible(user_agent) return !is_compatible(user_agent.to_s) end |
.is_uc_browser(user_agent) ⇒ Object
66 67 68 69 |
# File 'lib/should_send_same_site_none.rb', line 66 def self.is_uc_browser(user_agent) regex = /UCBrowser\// regex_contains(user_agent, regex) end |
.is_uc_browser_version_at_least(major, minor, build, user_agent) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/should_send_same_site_none.rb', line 71 def self.is_uc_browser_version_at_least(major, minor, build, user_agent) regex = /UCBrowser\/(\d+)\.(\d+)\.(\d+)[\.\d]* / major_version = extract_regex_match(user_agent, regex, 1).to_i minor_version = extract_regex_match(user_agent, regex, 2).to_i build_version = extract_regex_match(user_agent, regex, 3).to_i if (major_version != major) return major_version > major end if (minor_version != minor) return minor_version > minor end return build_version >= build end |
.regex_contains(string_value, regex) ⇒ Object
97 98 99 100 |
# File 'lib/should_send_same_site_none.rb', line 97 def self.regex_contains(string_value, regex) matches = string_value.match(regex) unless string_value.nil? return matches != nil end |