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

ruby-changes:66302

From: nagachika <ko1@a...>
Date: Sat, 22 May 2021 16:47:46 +0900 (JST)
Subject: [ruby-changes:66302] af9de56c6f (ruby_3_0): merge revision(s) 110f242ef9b495037f59e4972ee102a8b8b372d5: [Backport #17861]

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

From af9de56c6fde7f9adb81d6ed0ef3067af81f90e5 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Sat, 22 May 2021 16:47:24 +0900
Subject: merge revision(s) 110f242ef9b495037f59e4972ee102a8b8b372d5: [Backport
 #17861]

	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(-)
---
 parse.y                 | 12 ++++++++++--
 test/ruby/test_parse.rb | 15 +++++++++++++++
 version.h               |  2 +-
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/parse.y b/parse.y
index ca55b96..b111202 100644
--- a/parse.y
+++ b/parse.y
@@ -6763,7 +6763,11 @@ read_escape(struct parser_params *p, int flags, rb_encoding **encp) https://github.com/ruby/ruby/blob/trunk/parse.y#L6763
 	    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;
@@ -6788,7 +6792,11 @@ read_escape(struct parser_params *p, int flags, rb_encoding **encp) https://github.com/ruby/ruby/blob/trunk/parse.y#L6792
       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 5f638af..d316a00 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
diff --git a/version.h b/version.h
index 9ba6754..643f264 100644
--- a/version.h
+++ b/version.h
@@ -12,7 +12,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L12
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 2
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 80
+#define RUBY_PATCHLEVEL 81
 
 #define RUBY_RELEASE_YEAR 2021
 #define RUBY_RELEASE_MONTH 5
-- 
cgit v1.1


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

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