summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2023-07-17 18:04:41 +0900
committernagachika <nagachika@ruby-lang.org>2023-07-17 18:04:41 +0900
commit3f6187a94797d3c4a7db00563a885e4e613b51cf (patch)
treeb5efad788c4e5a49e7fc4c675bb414b05944c025 /test/ruby
parentaef53162249ce090568e24a70e6d26b85bf399d6 (diff)
merge revision(s) 1bc8838d60ef3fc6812d3b64ed87caaf0ae943d9: [Backport #19750]
Handle unterminated unicode escapes in regexps This fixes an infinite loop possible after ec3542229b29ec93062e9d90e877ea29d3c19472. For \u{} escapes in regexps, skip validation in the parser, and rely on the regexp code to handle validation. This is necessary so that invalid unicode escapes in comments in extended regexps are allowed. Fixes [Bug #19750] Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> --- parse.y | 97 ++++++++++++++++++++++++++++++++----------------- test/ruby/test_parse.rb | 16 ++++++++ 2 files changed, 79 insertions(+), 34 deletions(-)
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_parse.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 4488ea620e..a22f11aeae 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -1041,6 +1041,22 @@ x = __ENCODING__
assert_syntax_error(" 0b\n", /\^/)
end
+ def test_unclosed_unicode_escape_at_eol_bug_19750
+ assert_separately([], "#{<<-"begin;"}\n#{<<~'end;'}")
+ begin;
+ assert_syntax_error("/\\u", /too short escape sequence/)
+ assert_syntax_error("/\\u{", /unterminated regexp meets end of file/)
+ assert_syntax_error("/\\u{\\n", /invalid Unicode list/)
+ assert_syntax_error("/a#\\u{\\n/", /invalid Unicode list/)
+ re = eval("/a#\\u{\n$/x")
+ assert_match(re, 'a')
+ assert_not_match(re, 'a#')
+ re = eval("/a#\\u\n$/x")
+ assert_match(re, 'a')
+ assert_not_match(re, 'a#')
+ end;
+ end
+
def test_error_def_in_argument
assert_separately([], "#{<<-"begin;"}\n#{<<~"end;"}")
begin;