From 0680e9c0c16a7d900e3564e1836b8cb93d962a2b Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 25 Nov 2015 12:32:34 -0500 Subject: [PATCH] regexp/syntax: fix handling of \Q...\E It's not a group: must handle the inside as a sequence of literal chars, not a single literal string. That is, \Qab\E+ is the same as ab+, not (ab)+. Fixes #11187. Change-Id: I5406d05ccf7efff3a7f15395bdb0cfb2bd23a8ed Reviewed-on: https://go-review.googlesource.com/17233 Reviewed-by: David Crawshaw Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/regexp/syntax/parse.go | 9 ++++++++- src/regexp/syntax/parse_test.go | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/regexp/syntax/parse.go b/src/regexp/syntax/parse.go index d579a4069b160..c2b92c1d44ab4 100644 --- a/src/regexp/syntax/parse.go +++ b/src/regexp/syntax/parse.go @@ -830,7 +830,14 @@ func Parse(s string, flags Flags) (*Regexp, error) { lit = t[2:i] t = t[i+2:] } - p.push(literalRegexp(lit, p.flags)) + for lit != "" { + c, rest, err := nextRune(lit) + if err != nil { + return nil, err + } + p.literal(c) + lit = rest + } break BigSwitch case 'z': p.op(OpEndText) diff --git a/src/regexp/syntax/parse_test.go b/src/regexp/syntax/parse_test.go index c4a1117ff86ce..626ceeadf6d72 100644 --- a/src/regexp/syntax/parse_test.go +++ b/src/regexp/syntax/parse_test.go @@ -144,6 +144,7 @@ var parseTests = []parseTest{ // Test Perl quoted literals {`\Q+|*?{[\E`, `str{+|*?{[}`}, {`\Q+\E+`, `plus{lit{+}}`}, + {`\Qab\E+`, `cat{lit{a}plus{lit{b}}}`}, {`\Q\\E`, `lit{\}`}, {`\Q\\\E`, `str{\\}`}, @@ -479,6 +480,7 @@ var invalidRegexps = []string{ `a{100000}`, `a{100000,}`, "((((((((((x{2}){2}){2}){2}){2}){2}){2}){2}){2}){2})", + `\Q\E*`, } var onlyPerl = []string{