Fix RegexParser to ignore vertical tabs with RegexOptions.IgnorePatternWhitespace#120625
Merged
stephentoub merged 3 commits intomainfrom Oct 17, 2025
Merged
Fix RegexParser to ignore vertical tabs with RegexOptions.IgnorePatternWhitespace#120625stephentoub merged 3 commits intomainfrom
stephentoub merged 3 commits intomainfrom
Conversation
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix regex parser to ignore vertical tabs with IgnorePatternWhiteSpace
Fix RegexParser to ignore vertical tabs with RegexOptions.IgnorePatternWhitespace
Oct 11, 2025
stephentoub
reviewed
Oct 11, 2025
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Match.Tests.cs
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in the regex parser where vertical tab (\v, character 0xB) was not being treated as whitespace when using RegexOptions.IgnorePatternWhitespace, making it inconsistent with other .NET APIs and regex engines like PCRE2.
- Updated the ASCII character category table to mark vertical tab as whitespace
- Added vertical tab to the metacharacters SearchValues for proper escaping
- Added test case to verify vertical tab is properly ignored with IgnorePatternWhitespace option
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| RegexParser.cs | Updated character category table to treat vertical tab as whitespace and added \v to metacharacters |
| Regex.Match.Tests.cs | Added test case verifying vertical tab is ignored with IgnorePatternWhitespace option |
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
stephentoub
approved these changes
Oct 11, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fix: Regex parser to ignore vertical tabs in pattern with RegexOptions.IgnorePatternWhitespace
Plan:
\v, 0xB) is not ignored with IgnorePatternWhitespaceChanges Made:
\vto s_metachars SearchValuesif (!PlatformDetection.IsNetFramework)to prevent failures on .NET FrameworkTest Results:
✅ FunctionalTests: 29,291 tests passed, 0 failures
✅ UnitTests: 1,005 tests passed, 0 failures
✅ New test case: Verified passing across all regex engines (Interpreter, Compiled, NonBacktracking, SourceGenerated) on .NET Core
Technical Details:
Original prompt
Fixes #73206
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.