Skip to content

Fix ApacheModRewrite tokenizer throwing on regex shorthand escapes - #68788

Open
SergioAlmeida29 wants to merge 1 commit into
dotnet:mainfrom
SergioAlmeida29:fix/18555-apache-modrewrite-regex-escapes
Open

Fix ApacheModRewrite tokenizer throwing on regex shorthand escapes#68788
SergioAlmeida29 wants to merge 1 commit into
dotnet:mainfrom
SergioAlmeida29:fix/18555-apache-modrewrite-regex-escapes

Conversation

@SergioAlmeida29

Copy link
Copy Markdown
  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Summary of the changes (Less than 80 chars)

Stop unescaping regex shorthand sequences like \d in ApacheModRewrite tokens

Description

Tokenizer.RemoveQuotesAndEscapeCharacters ran every token through Regex.Unescape, which throws ArgumentException for valid regex escapes such as \d, \w or \s and silently corrupted \b into a backspace character. Replaced it with an unescape step that preserves the previous decoding for everything it accepted (escaped spaces/quotes/backslashes, control characters, \xHH, \uHHHH, octal escapes) while passing regex escape sequences through to the regex engine unchanged. All previously-accepted inputs decode identically.

Fixes #18555

Tokenizer.RemoveQuotesAndEscapeCharacters ran every token through
Regex.Unescape, which throws ArgumentException for valid regex escape
sequences such as \d, \w or \s, making AddApacheModRewrite unusable for
standard mod_rewrite rules using shorthand character classes. It also
silently corrupted patterns like \b by decoding it to a backspace
character instead of a word boundary.

Replace Regex.Unescape with a dedicated unescape step that keeps the
previous decoding for everything it accepted (escaped spaces, quotes,
backslashes, control characters, \xHH, \uHHHH and octal escapes) while
leaving regex escape sequences untouched so they are interpreted by the
regex engine.

Fixes dotnet#18555

Signed-off-by: Sergio Almeida <sergioalmeida29.05@gmail.com>
Copilot AI lite review requested due to automatic review settings August 25, 2026 23:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Aug 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @SergioAlmeida29. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@SergioAlmeida29

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArgumentException "unrecognized escape sequence" in RewriteOptions.AddApacheModRewrite in case of usage of regex shorthand character classes (like \d)

2 participants