diff options
author | nagachika <[email protected]> | 2021-05-22 16:47:24 +0900 |
---|---|---|
committer | nagachika <[email protected]> | 2021-05-22 16:47:24 +0900 |
commit | af9de56c6fde7f9adb81d6ed0ef3067af81f90e5 (patch) | |
tree | 51766458ece2e3f456eb61510503d64a20fadafb | |
parent | 5e21726cda22e3cb34127751aec7e9babb4308b3 (diff) |
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(-)
-rw-r--r-- | parse.y | 12 | ||||
-rw-r--r-- | test/ruby/test_parse.rb | 15 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 26 insertions, 3 deletions
@@ -6763,7 +6763,11 @@ read_escape(struct parser_params *p, int flags, rb_encoding **encp) 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) 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 5f638afa01..d316a00b47 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -562,6 +562,21 @@ class TestParse < Test::Unit::TestCase 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 @@ -12,7 +12,7 @@ # 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 |