Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/device_detector/client_hint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def initialize(headers)
return if headers.nil?

@headers = headers
@full_version = headers['Sec-CH-UA-Full-Version']
@full_version = unquote(headers['Sec-CH-UA-Full-Version'])
@browser_list = extract_browser_list
@app_name = extract_app_name
@platform = headers['Sec-CH-UA-Platform']
@platform = unquote(headers['Sec-CH-UA-Platform'])
@platform_version = extract_platform_version
@mobile = headers['Sec-CH-UA-Mobile']
@model = extract_model
Expand Down Expand Up @@ -63,7 +63,7 @@ def extract_platform_version
return if headers['Sec-CH-UA-Platform-Version'].nil?
return if headers['Sec-CH-UA-Platform-Version'] == ''

headers['Sec-CH-UA-Platform-Version']
unquote(headers['Sec-CH-UA-Platform-Version'])
end

# https://github.com/matomo-org/device-detector/blob/28211c6f411528abf41304e07b886fdf322a49b7/Parser/OperatingSystem.php#L330
Expand Down Expand Up @@ -152,9 +152,9 @@ def extract_browser_list
end

def extract_browser_name_and_version(component)
component_and_version = component.gsub('"', '').split("\;v=")
component_and_version = unquote(component).split("\;v=")
name = name_from_known_browsers(component_and_version.first)
browser_version = full_version&.gsub('"', '') || component_and_version.last
browser_version = full_version || component_and_version.last
{ name: name, version: browser_version }
end

Expand All @@ -177,5 +177,9 @@ def extract_model

headers['Sec-CH-UA-Model']

Choose a reason for hiding this comment

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

I ran into this issue too. I believe we also need to unquote 'Sec-CH-UA-Model', which is also wrapped, at least on MacOS Chrome.

end

def unquote(str)
str&.gsub('"', '')
end
end
end
66 changes: 33 additions & 33 deletions spec/fixtures/client/browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4465,10 +4465,10 @@
family: Chrome
headers:
Sec-CH-UA: '" Not A;Brand";v="99.0.0.0", "Chromium";v="98.0.4758.109", "Gener8";v="98.0.4758.109"'
Sec-CH-UA-Platform: "Windows"
Sec-CH-UA-Platform: '"Windows"'
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, these kind of changes will be overwritten on the first fixtures sync from the upstream: fixtures are not updated manually. There is bundle exec rake update_fixtures specifically for that:

device_detector/Rakefile

Lines 69 to 88 in e68ee76

desc 'update fixtures from piwik project'
task :update_fixtures do
top = File.expand_path(__dir__)
get_latest_piwik_checkout
fixture_mappings = [
{ target_path: "#{top}/spec/fixtures/detector", source_path: 'Tests/fixtures/*.yml' },
{ target_path: "#{top}/spec/fixtures/client",
source_path: 'Tests/Parser/Client/fixtures/*.yml' },
{ target_path: "#{top}/spec/fixtures/parser", source_path: 'Tests/Parser/fixtures/*.yml' },
{ target_path: "#{top}/spec/fixtures/device",
source_path: 'Tests/Parser/Device/fixtures/*.yml' }
]
fixture_mappings.each do |mapping|
source_path = mapping.fetch(:source_path)
target_path = mapping.fetch(:target_path)
system "cp -R #{PIWIK_CHECKOUT_LOCATION}/#{source_path} #{target_path}"
end
end

I would suggest to add a dedicated test for the unquote functionality outside of the existing fixtures. Some examples can be found in here: https://github.com/podigee/device_detector/tree/develop/spec/device_detector

Sec-CH-UA-Mobile: "?0"
Sec-CH-UA-Full-Version: "98.0.4758.109"
Sec-CH-UA-Platform-Version: "10.0.0"
Sec-CH-UA-Full-Version: '"98.0.4758.109"'
Sec-CH-UA-Platform-Version: '"10.0.0"'
Sec-CH-UA-Arch: "x86"
Sec-CH-UA-Bitness: "64"
Sec-CH-Prefers-Color-Scheme: "light"
Expand All @@ -4483,10 +4483,10 @@
family: Opera
headers:
Sec-CH-UA: '" Not A;Brand";v="99.0.0.0", "Chromium";v="99.0.4844.16", "Opera Crypto";v="99.0.4844.16"'
Sec-CH-UA-Platform: "Windows"
Sec-CH-UA-Platform: '"Windows"'
Sec-CH-UA-Mobile: "?0"
Sec-CH-UA-Full-Version: "99.0.4844.16"
Sec-CH-UA-Platform-Version: "10.0.0"
Sec-CH-UA-Full-Version: '"99.0.4844.16"'
Sec-CH-UA-Platform-Version: '"10.0.0"'
Sec-CH-UA-Arch: "x86"
Sec-CH-UA-Bitness: "64"
Sec-CH-Prefers-Color-Scheme: "dark"
Expand All @@ -4501,10 +4501,10 @@
family: Chrome
headers:
Sec-CH-UA: '" Not A;Brand";v="99.0.0.0", "Chromium";v="98", "Whale";v="3.13.131.36"'
Sec-CH-UA-Platform: "Windows"
Sec-CH-UA-Platform: '"Windows"'
Sec-CH-UA-Mobile: "?0"
Sec-CH-UA-Full-Version: "3.13.131.36"
Sec-CH-UA-Platform-Version: "14.0.0"
Sec-CH-UA-Full-Version: '"3.13.131.36"'
Sec-CH-UA-Platform-Version: '"14.0.0"'
Sec-CH-UA-Arch: "x86"
Sec-CH-UA-Bitness: "64"
Sec-CH-Prefers-Color-Scheme: "light"
Expand All @@ -4519,10 +4519,10 @@
family: Opera
headers:
Sec-CH-UA: '" Not A;Brand";v="99.0.0.0", "Chromium";v="98.0.4758.102", "Opera GX";v="98.0.4758.102"'
Sec-CH-UA-Platform: "Windows"
Sec-CH-UA-Platform: '"Windows"'
Sec-CH-UA-Mobile: "?0"
Sec-CH-UA-Full-Version: "98.0.4758.102"
Sec-CH-UA-Platform-Version: "14.0.0"
Sec-CH-UA-Full-Version: '"98.0.4758.102"'
Sec-CH-UA-Platform-Version: '"14.0.0"'
Sec-CH-UA-Arch: "x86"
Sec-CH-UA-Bitness: "64"
Sec-CH-Prefers-Color-Scheme: "dark"
Expand Down Expand Up @@ -6040,7 +6040,7 @@
family: Chrome
headers:
Sec-CH-UA: '"(Not(A:Brand";v="8.0.0.0", "WaveBrowser";v="1.1.6.4", "WaveBrowser";v="1.1.6.4"'
Sec-CH-UA-Platform: 'Windows'
Sec-CH-UA-Platform: '"Windows"'
Sec-CH-UA-Mobile: '?0'
-
user_agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36
Expand All @@ -6053,7 +6053,7 @@
family: Chrome
headers:
Sec-CH-UA: '" Not A;Brand";v="99.0.0.0", "Chromium";v="99.0.15185.77", "CCleaner Browser";v="99.0.15185.77"'
Sec-CH-UA-Platform: 'Windows'
Sec-CH-UA-Platform: '"Windows"'
Sec-CH-UA-Mobile: '?0'
-
user_agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.132 Safari/537.36
Expand All @@ -6066,7 +6066,7 @@
family: Chrome
headers:
Sec-CH-UA: '" Not A;Brand";v="99", "Chromium";v="98", "Sidekick";v="98"'
Sec-CH-UA-Platform: 'macOS'
Sec-CH-UA-Platform: '"macOS"'
Sec-CH-UA-Mobile: '?0'
-
user_agent: 'Opera%20GX/416.0.0 CFNetwork/1331.0.7 Darwin/21.4.0'
Expand Down Expand Up @@ -6472,7 +6472,7 @@
family: Chrome
headers:
Sec-CH-UA: '" Not A;Brand";v="99.0.0.0", "Chromium";v="2022.04"'
Sec-CH-UA-Platform: 'Linux'
Sec-CH-UA-Platform: '"Linux"'
Sec-CH-UA-Mobile: '?0'
-
user_agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.148 Atom/23.0.0.28 Safari/537.36
Expand All @@ -6485,7 +6485,7 @@
family: Chrome
headers:
Sec-CH-UA: '" Not A;Brand";v="99", "Chromium";v="102", "Atom";v="23"'
Sec-CH-UA-Platform: "Windows"
Sec-CH-UA-Platform: '"Windows"'
Sec-CH-UA-Mobile: "?0"
-
user_agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.148 Atom/23.0.0.28 Safari/537.36
Expand All @@ -6498,10 +6498,10 @@
family: Chrome
headers:
Sec-CH-UA: '" Not A;Brand";v="99.0.0.0", "Chromium";v="102.0.5005.148", "Atom";v="23.0.0.28"'
Sec-CH-UA-Platform: "Windows"
Sec-CH-UA-Platform: '"Windows"'
Sec-CH-UA-Mobile: "?0"
Sec-CH-UA-Full-Version: "102.0.5005.148"
Sec-CH-UA-Platform-Version: "10.0.0"
Sec-CH-UA-Full-Version: '"102.0.5005.148"'
Sec-CH-UA-Platform-Version: '"10.0.0"'
Sec-CH-UA-Arch: "x86"
Sec-CH-UA-Bitness: "64"
Sec-CH-Prefers-Color-Scheme: "light"
Expand All @@ -6516,7 +6516,7 @@
family: Chrome
headers:
Sec-CH-UA: '"Chromium";v="103", ".Not/A)Brand";v="99"'
Sec-CH-UA-Platform: "Windows"
Sec-CH-UA-Platform: '"Windows"'
Sec-CH-UA-Mobile: "?0"
-
user_agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.88 Safari/537.36 OPR/85.0.4341.13
Expand All @@ -6529,10 +6529,10 @@
family: Opera
headers:
Sec-CH-UA: '" Not A;Brand";v="99.0.0.0", "Chromium";v="99.0.4844.88"'
Sec-CH-UA-Platform: "Android"
Sec-CH-UA-Platform: '"Android"'
Sec-CH-UA-Mobile: "?0"
Sec-CH-UA-Full-Version: "99.0.4844.88"
Sec-CH-UA-Platform-Version: "9.0.0"
Sec-CH-UA-Full-Version: '"99.0.4844.88"'
Sec-CH-UA-Platform-Version: '"9.0.0"'
Sec-CH-UA-Model: "STF-L09"
Sec-CH-Prefers-Color-Scheme: "light"
-
Expand Down Expand Up @@ -7127,7 +7127,7 @@
family: Chrome
headers:
Sec-CH-UA: '"(Not(A:Brand";v="8", "Chromium";v="2022"'
Sec-CH-UA-Platform: 'Windows'
Sec-CH-UA-Platform: '"Windows"'
Sec-CH-UA-Mobile: '?0'
-
user_agent: Mozilla/5.0 (Linux; Android 10; VOG-L29; HMSCore 6.6.0.352; GMSCore 22.26.15) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.105 HuaweiBrowser/12.1.3.301 Mobile Safari/537.36
Expand All @@ -7152,7 +7152,7 @@
family: Chrome
headers:
Sec-CH-UA: '"Chromium";v="106", "Brave";v="106", "Not;A=Brand";v="99"'
Sec-CH-UA-Platform: "Android"
Sec-CH-UA-Platform: '"Android"'
Sec-CH-UA-Mobile: "?1"
-
user_agent: Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Mobile Safari/537.36
Expand All @@ -7165,7 +7165,7 @@
family: Chrome
headers:
Sec-CH-UA: '"Chromium";v="106", "Brave Browser";v="106", "Not;A=Brand";v="99"'
Sec-CH-UA-Platform: "Android"
Sec-CH-UA-Platform: '"Android"'
Sec-CH-UA-Mobile: "?1"
-
user_agent: Mozilla/5.0 (X11; Linux x86_64; Quest 2) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/24.3.0.4.63.416895357 SamsungBrowser/4.0 Chrome/106.0.5249.168 VR Safari/537.36
Expand All @@ -7178,7 +7178,7 @@
family: Chrome
headers:
Sec-CH-UA: '"Chromium";v="106", "Oculus Browser";v="24", "Not;A=Brand";v="99"'
Sec-CH-UA-Platform: "Linux"
Sec-CH-UA-Platform: '"Linux"'
Sec-CH-UA-Mobile: "?0"
-
user_agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
Expand All @@ -7191,7 +7191,7 @@
family: Chrome
headers:
Sec-CH-UA: '"Chromium";v="2021", ";Not A Brand";v="99"'
Sec-CH-UA-Platform: "Windows"
Sec-CH-UA-Platform: '"Windows"'
Sec-CH-UA-Mobile: "?0"
Sec-CH-UA-Full-Version: '"2021.12"'
-
Expand Down Expand Up @@ -7250,7 +7250,7 @@
family: Chrome
headers:
Sec-CH-UA: '"Wavebox";v="111", "Not(A:Brand";v="8", "Chromium";v="111"'
Sec-CH-UA-Platform: 'macOS'
Sec-CH-UA-Platform: '"macOS"'
Sec-CH-UA-Mobile: '?0'
-
user_agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36 Edg/86.0.622.69
Expand All @@ -7263,7 +7263,7 @@
family: Internet Explorer
headers:
Sec-CH-UA: 'Microsoft Edge;v="86", "Chromium";v="86", ";Not A Brand";v="99"'
Sec-CH-UA-Platform: 'Windows'
Sec-CH-UA-Platform: '"Windows"'
Sec-CH-UA-Mobile: '?0'
-
user_agent: Mozilla/5.0 (Linux; Android 4.4.2; SM-P600) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
Expand Down Expand Up @@ -7342,7 +7342,7 @@
family: Chrome
headers:
Sec-CH-UA: '"HeadlessChrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"'
Sec-CH-UA-Platform: 'Linux'
Sec-CH-UA-Platform: '"Linux"'
Sec-CH-UA-Mobile: '?0'
-
user_agent: ddg_android/5.114.3 (com.duckduckgo.mobile.android; Android API 22)
Expand Down Expand Up @@ -7547,7 +7547,7 @@
family: Chrome
headers:
Sec-CH-UA: '"Chromium";v="116.0.22144.111", "Not)A;Brand";v="24.0.0.0", "Avira Secure Browser";v="116.0.22144.111"'
Sec-CH-UA-Full-Version: "116.0.22144.111"
Sec-CH-UA-Full-Version: '"116.0.22144.111"'
-
user_agent: Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-A146U) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/23.0 Chrome/115.0.0.0 Mobile Safari/537.36
client:
Expand Down
Loading