Skip to content

Conversation

BenjaminAbt
Copy link
Member

@BenjaminAbt BenjaminAbt requested a review from Copilot August 25, 2025 07:48
Copy link

@Copilot Copilot AI left a 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.

@BenjaminAbt BenjaminAbt requested a review from gfoidl August 25, 2025 07:55
@BenjaminAbt BenjaminAbt merged commit 3006600 into main Aug 25, 2025
2 checks passed
@BenjaminAbt BenjaminAbt deleted the feature/unknown-should-not-throw-ex branch August 25, 2025 10:59
Copy link
Contributor

@gfoidl gfoidl left a 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')
Copy link
Contributor

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 == '.'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TryExtractVersion throws Exception on invalid user agents
2 participants