[前][次][番号順一覧][スレッド一覧]

ruby-changes:66196

From: Nobuyoshi <ko1@a...>
Date: Thu, 13 May 2021 12:59:40 +0900 (JST)
Subject: [ruby-changes:66196] 110f242ef9 (master): Also `\U` after control/meta is invalid [Bug #17861]

https://git.ruby-lang.org/ruby.git/commit/?id=110f242ef9

From 110f242ef9b495037f59e4972ee102a8b8b372d5 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 13 May 2021 12:30:48 +0900
Subject: Also `\U` after control/meta is invalid [Bug #17861]

As well as `\u`, `\U` should be invalid there too.
And highlight including `u`/`U` not only the backslash before it.
---
 parse.y                 | 12 ++++++++++--
 test/ruby/test_parse.rb | 15 +++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/parse.y b/parse.y
index 66813e5..3a03a3e 100644
--- a/parse.y
+++ b/parse.y
@@ -6825,7 +6825,11 @@ read_escape(struct parser_params *p, int flags, rb_encoding **encp) https://github.com/ruby/ruby/blob/trunk/parse.y#L6825
 	    goto eof;
 	}
 	if ((c = nextc(p)) == '\\') {
-	    if (peek(p, 'u')) goto eof;
+	    switch (peekc(p)) {
+	      case 'u': case 'U':
+		nextc(p);
+		goto eof;
+	    }
 	    return read_escape(p, flags|ESCAPE_META, encp) | 0x80;
 	}
 	else if (c == -1 || !ISASCII(c)) goto eof;
@@ -6850,7 +6854,11 @@ read_escape(struct parser_params *p, int flags, rb_encoding **encp) https://github.com/ruby/ruby/blob/trunk/parse.y#L6854
       case 'c':
 	if (flags & ESCAPE_CONTROL) goto eof;
 	if ((c = nextc(p))== '\\') {
-	    if (peek(p, 'u')) goto eof;
+	    switch (peekc(p)) {
+	      case 'u': case 'U':
+		nextc(p);
+		goto eof;
+	    }
 	    c = read_escape(p, flags|ESCAPE_CONTROL, encp);
 	}
 	else if (c == '?')
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 493042e..0acbaed 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -562,6 +562,21 @@ class TestParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L562
     assert_syntax_error("\"\\M-\x01\"", 'Invalid escape character syntax')
     assert_syntax_error("\"\\M-\\C-\x01\"", 'Invalid escape character syntax')
     assert_syntax_error("\"\\C-\\M-\x01\"", 'Invalid escape character syntax')
+
+    e = assert_syntax_error('"\c\u0000"', 'Invalid escape character syntax')
+    assert_equal(' ^~~~'"\n", e.message.lines.last)
+    e = assert_syntax_error('"\c\U0000"', 'Invalid escape character syntax')
+    assert_equal(' ^~~~'"\n", e.message.lines.last)
+
+    e = assert_syntax_error('"\C-\u0000"', 'Invalid escape character syntax')
+    assert_equal(' ^~~~~'"\n", e.message.lines.last)
+    e = assert_syntax_error('"\C-\U0000"', 'Invalid escape character syntax')
+    assert_equal(' ^~~~~'"\n", e.message.lines.last)
+
+    e = assert_syntax_error('"\M-\u0000"', 'Invalid escape character syntax')
+    assert_equal(' ^~~~~'"\n", e.message.lines.last)
+    e = assert_syntax_error('"\M-\U0000"', 'Invalid escape character syntax')
+    assert_equal(' ^~~~~'"\n", e.message.lines.last)
   end
 
   def test_question
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]