← Back to Pull requests

Fix Firefox regex to handle version without patch segment #530

Merged
karissekjw merged 2 files (10 lines) on May 20, 2023 07:59 UTC
View on GitHub
karissekjw karissekjw commented on Oct 26, 2022 03:08 UTC
Author

Update regex to allow patch segment as optional.

Current Issue


When parsing 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0' to https://github.com/ua-parser/uap-ruby, #<MatchData "Firefox/103.0" 1:"Firefox" 2:"104" 3:"0" 4:""> is returned which interpolates to Firefox 104.0. (Notice the additional . here due to the empty string in the patch segment)

Solution


With the updated regex, patch segment is optional such that it returns Firefox 104.0 if it's not provided

Diff: 10 lines (+8 / -2) across 2 files Reviewer: commenthol Review duration: 296931m
All Vouch review confidence checks passed
Residual risk 0.02 = Change Risk (0.19) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.19 · 10 lines diff across 2 files
0.19
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 2 substantive comment(s)
0.89
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
90%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.143
Real PR Conversation Timeline
3 items
commenthol commenthol commented on code on Jan 11, 2023 07:14 UTC
Code Review
regexes.yaml:1
@@ -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)'

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+)|)'?

karissekjw karissekjw commented on code on Jan 11, 2023 08:03 UTC
Code Review
regexes.yaml:1
@@ -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)'

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%20or%20line%20(m%3Dtrue))). It's also a common token used and is supported by Javascript. Let me know if this change sounds good to you too.

Reviewers
Assignees
karissekjw karissekjw
Labels
risk: low confidence: 90.6% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 18.8% (LOW) · Higher = larger blast radius
18.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 90.6% · Lower = rushed or shallow review
90.6%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 2% · Safe to merge
2%