Skip to content

Commit 83e6d1d

Browse files
committed
regexp: fix compiling alternate patterns of different fold case literals
Fixing Equal method in regexp/syntax package fixes compilation of some alternate patterns like "0A|0[aA]". Fixes golang#59007
1 parent 6dc99aa commit 83e6d1d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/regexp/find_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ var findTests = []FindTest{
9898
{`\B`, "x y", nil},
9999
{`\B`, "xx yy", build(2, 1, 1, 4, 4)},
100100
{`(|a)*`, "aa", build(3, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2)},
101+
{`0A|0[aA]`, "0a", build(1, 0, 2)},
102+
{`0[aA]|0A`, "0a", build(1, 0, 2)},
101103

102104
// RE2 tests
103105
{`[^\S\s]`, "abcd", nil},

src/regexp/syntax/regexp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (x *Regexp) Equal(y *Regexp) bool {
7676
}
7777

7878
case OpLiteral, OpCharClass:
79-
return slices.Equal(x.Rune, y.Rune)
79+
return x.Flags&FoldCase == y.Flags&FoldCase && slices.Equal(x.Rune, y.Rune)
8080

8181
case OpAlternate, OpConcat:
8282
return slices.EqualFunc(x.Sub, y.Sub, (*Regexp).Equal)

0 commit comments

Comments
 (0)