diff --git a/parse.y b/parse.y index 8f44534deb..f7349496cd 100644 --- a/parse.y +++ b/parse.y @@ -5999,7 +5999,7 @@ parser_tokadd_utf8(struct parser_params *parser, rb_encoding **encp, int c, last = nextc(); if (lex_p >= lex_pend) goto unterminated; while (ISSPACE(c = *lex_p) && ++lex_p < lex_pend); - do { + while (c != close_brace) { if (regexp_literal) tokadd(last); if (!parser_tokadd_codepoint(parser, encp, regexp_literal, TRUE)) { break; @@ -6008,7 +6008,7 @@ parser_tokadd_utf8(struct parser_params *parser, rb_encoding **encp, if (++lex_p >= lex_pend) goto unterminated; last = c; } - } while (c != close_brace); + } if (c != close_brace) { unterminated: diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 8830dbec30..dc461e6599 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -517,6 +517,8 @@ class TestParse < Test::Unit::TestCase assert_syntax_error(src, /:#{__LINE__}: unterminated/o) assert_syntax_error('"\u{100000000}"', /invalid Unicode escape/) + assert_equal("", eval('"\u{}"')) + assert_equal("", eval('"\u{ }"')) assert_equal("\x81", eval('"\C-\M-a"')) assert_equal("\177", eval('"\c?"')) @@ -555,6 +557,10 @@ class TestParse < Test::Unit::TestCase assert_nothing_raised(SyntaxError, bug) do assert_equal(sym, eval(':"foo\u{0}bar"')) end + assert_nothing_raised(SyntaxError) do + assert_equal(:foobar, eval(':"foo\u{}bar"')) + assert_equal(:foobar, eval(':"foo\u{ }bar"')) + end end def test_parse_string