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

ruby-changes:55967

From: Nobuyoshi <ko1@a...>
Date: Mon, 3 Jun 2019 15:18:39 +0900 (JST)
Subject: [ruby-changes:55967] Nobuyoshi Nakada: c990b3c41a (trunk): Fix the error token on "invalid hex escape"

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

From c990b3c41af5957a739dfb235dfbb821e73a74df Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 3 Jun 2019 14:56:42 +0900
Subject: Fix the error token on "invalid hex escape"

* parse.y (tok_hex): flush token after dispatching the "invalid
  hex escape" parse error.

diff --git a/parse.y b/parse.y
index 58b8714..311bbba 100644
--- a/parse.y
+++ b/parse.y
@@ -6133,8 +6133,8 @@ tok_hex(struct parser_params *p, size_t *numlen) https://github.com/ruby/ruby/blob/trunk/parse.y#L6133
 
     c = scan_hex(p->lex.pcur, 2, numlen);
     if (!*numlen) {
-	p->lex.ptok = p->lex.pcur;
 	yyerror0("invalid hex escape");
+	token_flush(p);
 	return 0;
     }
     p->lex.pcur += *numlen;
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index 0b4814a..339a66d 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -976,4 +976,14 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_scanner_events.rb#L976
     assert_match /Invalid char/, err[1]
     assert_equal "\e", err[2]
   end
+
+  def test_invalid_hex_escape
+    err = nil
+    assert_equal ['U'], scan('tstring_content', '"\\xU"') {|*e| err = e}
+    assert_equal [:on_parse_error, "invalid hex escape", "\\x"], err
+
+    err = nil
+    assert_equal ['U'], scan('tstring_content', '/\\xU/') {|*e| err = e}
+    assert_equal [:on_parse_error, "invalid hex escape", "\\x"], err
+  end
 end if ripper_test
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index fca8d74..ff62aef 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -513,7 +513,7 @@ class TestParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L513
     mesg = 'from the backslash through the invalid char'
 
     e = assert_syntax_error('"\xg1"', /hex escape/)
-    assert_equal('   ^', e.message.lines.last, mesg)
+    assert_equal(' ^~', e.message.lines.last, mesg)
 
     e = assert_syntax_error('"\u{1234"', 'unterminated Unicode escape')
     assert_equal('        ^', e.message.lines.last, mesg)
-- 
cgit v0.10.2


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

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