Skip to content

Commit 5100f8a

Browse files
Add test fixture for malformed regex capture name escape encoding
1 parent c23d8bc commit 5100f8a

6 files changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@ ProgramNode (location: (1,0)-(2,18))
2+
├── flags: ∅
3+
├── locals: []
4+
└── statements:
5+
@ StatementsNode (location: (1,0)-(2,18))
6+
├── flags: ∅
7+
└── body: (length: 2)
8+
├── @ CallNode (location: (1,0)-(1,27))
9+
│ ├── flags: newline
10+
│ ├── receiver:
11+
│ │ @ RegularExpressionNode (location: (1,0)-(1,18))
12+
│ │ ├── flags: static_literal, forced_us_ascii_encoding
13+
│ │ ├── opening_loc: (1,0)-(1,1) = "/"
14+
│ │ ├── content_loc: (1,1)-(1,17) = "(?<\\u{21!3}>foo)"
15+
│ │ ├── closing_loc: (1,17)-(1,18) = "/"
16+
│ │ └── unescaped: "(?<\\u{21!3}>foo)"
17+
│ ├── call_operator_loc: ∅
18+
│ ├── name: :=~
19+
│ ├── message_loc: (1,19)-(1,21) = "=~"
20+
│ ├── opening_loc: ∅
21+
│ ├── arguments:
22+
│ │ @ ArgumentsNode (location: (1,22)-(1,27))
23+
│ │ ├── flags: ∅
24+
│ │ └── arguments: (length: 1)
25+
│ │ └── @ StringNode (location: (1,22)-(1,27))
26+
│ │ ├── flags: ∅
27+
│ │ ├── opening_loc: (1,22)-(1,23) = "\""
28+
│ │ ├── content_loc: (1,23)-(1,26) = "foo"
29+
│ │ ├── closing_loc: (1,26)-(1,27) = "\""
30+
│ │ └── unescaped: "foo"
31+
│ ├── closing_loc: ∅
32+
│ ├── equal_loc: ∅
33+
│ └── block: ∅
34+
└── @ RegularExpressionNode (location: (2,0)-(2,18))
35+
├── flags: newline, static_literal, forced_us_ascii_encoding
36+
├── opening_loc: (2,0)-(2,1) = "/"
37+
├── content_loc: (2,1)-(2,17) = "(?<\\u{21!3}>foo)"
38+
├── closing_loc: (2,17)-(2,18) = "/"
39+
└── unescaped: "(?<\\u{21!3}>foo)"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/(?<\u{21!3}>foo)/ =~ "foo"
2+
/(?<\u{21!3}>foo)/

test/prism/lex_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class LexTest < TestCase
2020
# is a line continuation preceded by escaped backslashes. It should emit two, same
2121
# as if the backslashes are not present.
2222
"heredocs_with_fake_newlines.txt",
23+
# Prism is currently silent on malformed escapes in regexes
24+
"regex_capture_escape_encoding_malformed.txt"
2325
]
2426

2527
if RUBY_VERSION < "3.3.0"

test/prism/ruby/parser_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class ParserTest < TestCase
7676

7777
# https://bugs.ruby-lang.org/issues/21168#note-5
7878
"command_method_call_2.txt",
79+
80+
# Prism is currently silent on malformed escapes in regexes
81+
"regex_capture_escape_encoding_malformed.txt"
7982
]
8083

8184
# These files contain code that is being parsed incorrectly by the parser

test/prism/ruby/ripper_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class RipperTest < TestCase
5151
"dos_endings.txt",
5252
"heredocs_with_fake_newlines.txt",
5353
"heredocs_with_ignored_newlines.txt",
54+
"regex_capture_escape_encoding_malformed.txt",
5455
"seattlerb/block_call_dot_op2_brace_block.txt",
5556
"seattlerb/block_command_operation_colon.txt",
5657
"seattlerb/block_command_operation_dot.txt",

test/prism/ruby/ruby_parser_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class RubyParserTest < TestCase
4545
"not.txt",
4646
"patterns.txt",
4747
"regex.txt",
48+
"regex_capture_escape_encoding_malformed.txt",
4849
"seattlerb/and_multi.txt",
4950
"seattlerb/heredoc__backslash_dos_format.txt",
5051
"seattlerb/heredoc_bad_hex_escape.txt",

0 commit comments

Comments
 (0)