Skip to content

Commit c7f14a0

Browse files
committed
Do not support \x{..} notation in ECMAScript mode
1 parent b3e1096 commit c7f14a0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

regexp_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,21 @@ func TestECMAInvalidEscapeCharClass(t *testing.T) {
777777
}
778778
}
779779

780+
func TestECMAScriptXCurlyBraceEscape(t *testing.T) {
781+
re := MustCompile(`\x{20}`, ECMAScript)
782+
if m, err := re.MatchString(" "); err != nil {
783+
t.Fatal(err)
784+
} else if m {
785+
t.Fatal("Expected no match")
786+
}
787+
788+
if m, err := re.MatchString("xxxxxxxxxxxxxxxxxxxx"); err != nil {
789+
t.Fatal(err)
790+
} else if !m {
791+
t.Fatal("Expected match")
792+
}
793+
}
794+
780795
func TestNegateRange(t *testing.T) {
781796
re := MustCompile(`[\D]`, 0)
782797
if m, err := re.MatchString("A"); err != nil {

syntax/parser.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,8 +1663,11 @@ func (p *parser) scanCharEscape() (r rune, err error) {
16631663
case 'x':
16641664
// support for \x{HEX} syntax from Perl and PCRE
16651665
if p.charsRight() > 0 && p.rightChar(0) == '{' {
1666+
if p.useOptionE() {
1667+
return ch, nil
1668+
}
16661669
p.moveRight(1)
1667-
r, err = p.scanHexUntilBrace()
1670+
return p.scanHexUntilBrace()
16681671
} else {
16691672
r, err = p.scanHex(2)
16701673
}

0 commit comments

Comments
 (0)