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

Fix Firefox regex to handle version without patch segment #530

Merged
merged 4 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions regexes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ user_agent_parsers:
# AFTER THE EDGE CASES ABOVE!
# AFTER IE11
# BEFORE all other IE
- regex: '(Firefox)/(\d+)\.(\d+)\.(\d+)'
- regex: '(Firefox)/(\d+)\.(\d+)(?:\.(\d+)|\z)'
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if the \z assertion is supported by every regex-engine. JavaScript seams to not support (or ignore) it. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Assertions
Can you please change that to '(Firefox)/(\d+)\.(\d+)(?:\.(\d+)|)'?

Copy link
Contributor Author

@karissekjw karissekjw Jan 11, 2023

Choose a reason for hiding this comment

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

Hey thanks for getting back, you're right. However, the above doesn't seem to work as intended for Ruby. Specifically, the version for Firefox/4.0b9pre will result in 4.0 instead of 4.0b9pre

I've updated to (Firefox)/(\d+)\.(\d+)(?:\.(\d+)|$) instead, $ seems to have the same effect as \z (see ref). It's also a common token used and is supported by Javascript. Let me know if this change sounds good to you too.

- regex: '(Firefox)/(\d+)\.(\d+)(pre|[ab]\d+[a-z]*|)'


Expand Down Expand Up @@ -5549,7 +5549,7 @@ device_parsers:
device_replacement: 'Motorola$2'
brand_replacement: 'Motorola'
model_replacement: '$2'


##########
# nintendo
Expand Down
6 changes: 6 additions & 0 deletions test_resources/firefox_user_agent_strings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,12 @@ test_cases:
minor: '0'
patch: '1'

- user_agent_string: 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0'
family: 'Firefox'
major: '104'
minor: '0'
patch:

- user_agent_string: 'Mozilla/5.0 (X11; Linux armv7l; rv:2.1.1) Gecko/ Firefox/5.0.1'
family: 'Firefox'
major: '5'
Expand Down