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 #59007

Change-Id: Idd519c6841167f932899b0ada347fb90a38a765e
GitHub-Last-Rev: 6f43cbca63
GitHub-Pull-Request: golang/go#66165
Reviewed-on: https://go-review.googlesource.com/c/go/+/569735
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Mark Freeman <mark@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
itchyny 2025-07-04 22:59:25 +00:00 committed by Gopher Robot
parent b1e933d955
commit 3aa1b00081
2 changed files with 3 additions and 1 deletions

View file

@ -98,6 +98,8 @@ var findTests = []FindTest{
{`\B`, "x y", nil}, {`\B`, "x y", nil},
{`\B`, "xx yy", build(2, 1, 1, 4, 4)}, {`\B`, "xx yy", build(2, 1, 1, 4, 4)},
{`(|a)*`, "aa", build(3, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2)}, {`(|a)*`, "aa", build(3, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2)},
{`0A|0[aA]`, "0a", build(1, 0, 2)},
{`0[aA]|0A`, "0a", build(1, 0, 2)},
// RE2 tests // RE2 tests
{`[^\S\s]`, "abcd", nil}, {`[^\S\s]`, "abcd", nil},

View file

@ -76,7 +76,7 @@ func (x *Regexp) Equal(y *Regexp) bool {
} }
case OpLiteral, OpCharClass: case OpLiteral, OpCharClass:
return slices.Equal(x.Rune, y.Rune) return x.Flags&FoldCase == y.Flags&FoldCase && slices.Equal(x.Rune, y.Rune)
case OpAlternate, OpConcat: case OpAlternate, OpConcat:
return slices.EqualFunc(x.Sub, y.Sub, (*Regexp).Equal) return slices.EqualFunc(x.Sub, y.Sub, (*Regexp).Equal)