]> Cypherpunks.ru repositories - gostls13.git/commitdiff
regexp/syntax: exclude full range from String negation case
authorKeegan Carruthers-Smith <keegan.csmith@gmail.com>
Tue, 7 May 2019 13:49:56 +0000 (15:49 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 22 May 2019 04:43:25 +0000 (04:43 +0000)
If the char class is 0x0-0x10ffff we mistakenly would String that to `[^]`,
which is not a valid regex.

Fixes #31807

Change-Id: I9ceeaddc28b67b8e1de12b6703bcb124cc784556
Reviewed-on: https://go-review.googlesource.com/c/go/+/175679
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/regexp/syntax/parse_test.go
src/regexp/syntax/regexp.go

index fe3d2517615089095a16b577321bbcae4834672f..5581ba1ca5ee29bad6fb6c2ae314b513a01931ff 100644 (file)
@@ -185,6 +185,7 @@ var parseTests = []parseTest{
        {`(?-s).`, `dnl{}`},
        {`(?:(?:^).)`, `cat{bol{}dot{}}`},
        {`(?-s)(?:(?:^).)`, `cat{bol{}dnl{}}`},
+       {`[\s\S]a`, `cat{cc{0x0-0x10ffff}lit{a}}`},
 
        // RE2 prefix_tests
        {`abc|abd`, `cat{str{ab}cc{0x63-0x64}}`},
index ae5fa053f985fec026abe8f25aefa03af22766e9..3a4d2d201cd418b1a111bf6e905490d0797a6fc7 100644 (file)
@@ -139,7 +139,7 @@ func writeRegexp(b *strings.Builder, re *Regexp) {
                b.WriteRune('[')
                if len(re.Rune) == 0 {
                        b.WriteString(`^\x00-\x{10FFFF}`)
-               } else if re.Rune[0] == 0 && re.Rune[len(re.Rune)-1] == unicode.MaxRune {
+               } else if re.Rune[0] == 0 && re.Rune[len(re.Rune)-1] == unicode.MaxRune && len(re.Rune) > 2 {
                        // Contains 0 and MaxRune. Probably a negated class.
                        // Print the gaps.
                        b.WriteRune('^')