]> Cypherpunks repositories - gostls13.git/commitdiff
regexp: fix compiling alternate patterns of different fold case literals
authoritchyny <itchyny@cybozu.co.jp>
Fri, 4 Jul 2025 22:59:25 +0000 (22:59 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 30 Jul 2025 14:25:52 +0000 (07:25 -0700)
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: 6f43cbca6361c0d084a12abeec65d7c659a4fe61
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>

src/regexp/find_test.go
src/regexp/syntax/regexp.go

index 2edbe9b86e61547d11c50040e8a39150378371ab..49e9619cef9bda75b329be3c288d7c2b1bf3f22e 100644 (file)
@@ -98,6 +98,8 @@ var findTests = []FindTest{
        {`\B`, "x y", nil},
        {`\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)},
+       {`0A|0[aA]`, "0a", build(1, 0, 2)},
+       {`0[aA]|0A`, "0a", build(1, 0, 2)},
 
        // RE2 tests
        {`[^\S\s]`, "abcd", nil},
index f15d2051230464cebc2a04d43137302e37b8e986..499492884ef28efaac5417a1bcb0c28f7fc83428 100644 (file)
@@ -76,7 +76,7 @@ func (x *Regexp) Equal(y *Regexp) bool {
                }
 
        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:
                return slices.EqualFunc(x.Sub, y.Sub, (*Regexp).Equal)