Skip to content

Commit

Permalink
Fix a NonBacktracking subsumption checking rule for XY|X??Y (#79163)
Browse files Browse the repository at this point in the history
* Add test for subsumption rule bug

* Fix subsumption rule by adding missing check for nullability of X
  • Loading branch information
olsaarik authored Dec 7, 2022
1 parent 20af770 commit b85a99d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,9 @@ internal bool Subsumes(SymbolicRegexBuilder<TSet> builder, SymbolicRegexNode<TSe
// This structure arises from a folding rule in TryFold
if (left._kind == SymbolicRegexNodeKind.Concat && right._kind == SymbolicRegexNodeKind.Concat)
{
Debug.Assert(right._left is not null && right._right is not null);
Debug.Assert(left._left is not null && right._left is not null && right._right is not null);
SymbolicRegexNode<TSet> rl = right._left;
if (rl._kind == SymbolicRegexNodeKind.Loop && rl._lower == 0 && rl._upper == 1 && rl.IsLazy)
if (left._left.IsNullable && rl._kind == SymbolicRegexNodeKind.Loop && rl._lower == 0 && rl._upper == 1 && rl.IsLazy)
{
Debug.Assert(rl._left is not null);
if (TrySkipPrefix(left, rl._left, out SymbolicRegexNode<TSet>? tail))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,9 @@ public static IEnumerable<object[]> Match_MemberData()
//mixed lazy and eager counting
yield return ("z(a{0,5}|a{0,10}?)", "xyzaaaaaaaaaxyz", options, 0, 15, true, "zaaaaa");
}

// Test for a bug in NonBacktracking's subsumption rule for XY subsuming X??Y, which didn't check that X is nullable
yield return (@"XY|X??Y", "Y", RegexOptions.None, 0, 1, true, "Y");
}

[OuterLoop("Takes several seconds to run")]
Expand Down

0 comments on commit b85a99d

Please sign in to comment.