summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parse.y12
-rw-r--r--test/ruby/test_parse.rb15
2 files changed, 25 insertions, 2 deletions
diff --git a/parse.y b/parse.y
index 66813e5ecb7..3a03a3e030d 100644
--- a/parse.y
+++ b/parse.y
@@ -6825,7 +6825,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;
@@ -6850,7 +6854,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 493042ef672..0acbaed30f2 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