Skip to content

Commit

Permalink
Do not support \x{..} notation in ECMAScript mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dop251 committed Oct 7, 2020
1 parent b3e1096 commit c7f14a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,21 @@ func TestECMAInvalidEscapeCharClass(t *testing.T) {
}
}

func TestECMAScriptXCurlyBraceEscape(t *testing.T) {
re := MustCompile(`\x{20}`, ECMAScript)
if m, err := re.MatchString(" "); err != nil {
t.Fatal(err)
} else if m {
t.Fatal("Expected no match")
}

if m, err := re.MatchString("xxxxxxxxxxxxxxxxxxxx"); err != nil {
t.Fatal(err)
} else if !m {
t.Fatal("Expected match")
}
}

func TestNegateRange(t *testing.T) {
re := MustCompile(`[\D]`, 0)
if m, err := re.MatchString("A"); err != nil {
Expand Down
5 changes: 4 additions & 1 deletion syntax/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1663,8 +1663,11 @@ func (p *parser) scanCharEscape() (r rune, err error) {
case 'x':
// support for \x{HEX} syntax from Perl and PCRE
if p.charsRight() > 0 && p.rightChar(0) == '{' {
if p.useOptionE() {
return ch, nil
}
p.moveRight(1)
r, err = p.scanHexUntilBrace()
return p.scanHexUntilBrace()
} else {
r, err = p.scanHex(2)
}
Expand Down

0 comments on commit c7f14a0

Please sign in to comment.