Skip to content

Commit 84b5650

Browse files
committed
Support \g, \k without group id as literal escapes
[#65]
1 parent 74856d9 commit 84b5650

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/regexp_parser/scanner/scanner.rl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
utf8_4_byte = (0xf0..0xf4 0x80..0xbf 0x80..0xbf 0x80..0xbf);
129129

130130
non_literal_escape = char_type_char | anchor_char | escaped_ascii |
131-
group_ref | keep_mark | [xucCM];
131+
keep_mark | [xucCM];
132132

133133
non_set_escape = (anchor_char - 'b') | group_ref | keep_mark |
134134
multi_codepoint_char_type | [0-9cCM];

spec/scanner/escapes_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
include_examples 'scan', 'c\qt', 1 => [:escape, :literal, '\q', 1, 3]
1515

16+
# these incomplete ref/call sequences are treated as literal escapes by Ruby
17+
include_examples 'scan', 'c\gt', 1 => [:escape, :literal, '\g', 1, 3]
18+
include_examples 'scan', 'c\kt', 1 => [:escape, :literal, '\k', 1, 3]
19+
1620
include_examples 'scan', 'a\012c', 1 => [:escape, :octal, '\012', 1, 5]
1721
include_examples 'scan', 'a\0124', 1 => [:escape, :octal, '\012', 1, 5]
1822
include_examples 'scan', '\712+7', 0 => [:escape, :octal, '\712', 0, 4]

0 commit comments

Comments
 (0)