Fix ApacheModRewrite tokenizer throwing on regex shorthand escapes - #68788
Open
SergioAlmeida29 wants to merge 1 commit into
Open
Fix ApacheModRewrite tokenizer throwing on regex shorthand escapes#68788SergioAlmeida29 wants to merge 1 commit into
SergioAlmeida29 wants to merge 1 commit into
Conversation
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>
Contributor
|
Thanks for your PR, @SergioAlmeida29. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Author
|
@dotnet-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the changes (Less than 80 chars)
Stop unescaping regex shorthand sequences like
\din ApacheModRewrite tokensDescription
Tokenizer.RemoveQuotesAndEscapeCharactersran every token throughRegex.Unescape, which throwsArgumentExceptionfor valid regex escapes such as\d,\wor\sand silently corrupted\binto 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