-
Notifications
You must be signed in to change notification settings - Fork 9
feat(parser): enhance user agent parsing logic and add tests for inva… #76
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
Conversation
BenjaminAbt
commented
Aug 25, 2025
- fixes TryExtractVersion throws Exception on invalid user agents #75
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the user agent parsing logic to better handle invalid and malformed user agents by improving detection of browser name misspellings and implementing stricter validation patterns. It also removes the overly broad "Mozilla" detection rule that was causing false positives.
- Improved browser detection logic to require proper format (Token/) and prevent misspelling matches
- Added comprehensive test coverage for invalid and malformed user agents
- Removed generic Mozilla detection rule that was too permissive
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
HttpUserAgentParserTests.cs | Adds comprehensive test cases for invalid user agents including misspellings and malformed strings |
HttpUserAgentStatics.cs | Adds EdgiOS detection rule and removes overly broad Mozilla rule |
HttpUserAgentParser.cs | Enhances browser detection logic with stricter validation and improved version extraction |
README.md | Updates benchmark performance metrics reflecting the changes |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was on short holidays, so delayed review...
{ | ||
char c = haystack[i]; | ||
if (char.IsBetween(c, '0', '9')) | ||
if (c >= '0' && c <= '9') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is two comparisons now, instead of just one. Either use the uint
cast directly, or use char.IsBetween
which does the same thing but more readable IMO.
Only the JIT for .NET 10+ is able to optimize that to one comparison (by using the uint
cast).
{ | ||
return false; | ||
char c = haystack[end]; | ||
if (!((c >= '0' && c <= '9') || c == '.')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.