Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,9 @@ public SymbolicMatch FindMatch(RegexRunnerMode mode, ReadOnlySpan<char> input, i
}
else
{
Registers endRegisters = _containsAnyAnchor ?
// Use DefaultInputReader when pattern contains \Z anchor (needs special \n handling),
// otherwise use NoZAnchorOptimizedInputReader for correct capture tracking
Registers endRegisters = _containsEndZAnchor ?
FindSubcaptures<DefaultInputReader>(input, matchStart, matchEnd, perThreadData) :
FindSubcaptures<NoZAnchorOptimizedInputReader>(input, matchStart, matchEnd, perThreadData);
return new SymbolicMatch(matchStart, matchEnd - matchStart, endRegisters.CaptureStarts, endRegisters.CaptureEnds);
Expand Down Expand Up @@ -1481,9 +1483,9 @@ public static int GetPositionId(SymbolicRegexMatcher<TSet> matcher, ReadOnlySpan
{
if ((uint)pos < (uint)input.Length)
{
// Find the minterm, handling the special case for the last \n for states that start with a relevant anchor
// Find the minterm, handling the special case for the last \n for \Z anchor
int c = input[pos];
return c == '\n' && pos == input.Length - 1 ?
return c == '\n' && pos == input.Length - 1 && matcher._containsEndZAnchor ?
matcher._minterms.Length : // mintermId = minterms.Length represents an \n at the very end of input
matcher._mintermClassifier.GetMintermID(c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,17 @@ public static IEnumerable<object[]> Groups_MemberData()
yield return (enUS, @"^(cat)\s+(dog)", "cat \n\n\n dog", RegexOptions.None, new string[] { "cat \n\n\n dog", "cat", "dog" });
yield return (enUS, @"^(cat)\s+(dog)", "cat \n\n\n dog", RegexOptions.Multiline, new string[] { "cat \n\n\n dog", "cat", "dog" });
yield return (enUS, @"(mouse)\s\n^(cat)\s+(dog)", "mouse\n\ncat \n\n\n dog", RegexOptions.Multiline, new string[] { "mouse\n\ncat \n\n\n dog", "mouse", "cat", "dog" });

// Regression test for https://github.com/dotnet/runtime/issues/120202
// Capture groups with beginning anchor and newline at end should work correctly with different end anchors
yield return (enUS, @"^(A)(\s)", "A\n", RegexOptions.None, new string[] { "A\n", "A", "\n" });
yield return (enUS, @"^(A)(\s)\z", "A\n", RegexOptions.None, new string[] { "A\n", "A", "\n" });
yield return (enUS, @"^(A)(\s)$", "A\n", RegexOptions.None, new string[] { "A\n", "A", "\n" });
yield return (enUS, @"^(A)(\s)\Z", "A\n", RegexOptions.None, new string[] { "A\n", "A", "\n" });
yield return (enUS, @"(A)(\s)\z", "A\n", RegexOptions.None, new string[] { "A\n", "A", "\n" }); // without beginning anchor
yield return (enUS, @"^(A)(\s)", "A\n", RegexOptions.Multiline, new string[] { "A\n", "A", "\n" });
yield return (enUS, @"^(A)(\s)", "A ", RegexOptions.None, new string[] { "A ", "A", " " });

if (!RegexHelpers.IsNonBacktracking(engine)) // ECMAScript not supported
{
yield return (enUS, @"^cat\s+dog", "cat \n\n\n dog", RegexOptions.ECMAScript, new string[] { "cat \n\n\n dog" });
Expand Down
Loading