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

ruby-changes:55866

From: Nobuyoshi <ko1@a...>
Date: Mon, 27 May 2019 23:14:42 +0900 (JST)
Subject: [ruby-changes:55866] Nobuyoshi Nakada: b4365e75fd (trunk): Do not make an incomplete escape a valid char

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

From b4365e75fd70618b79b3a71c1c13f202acd71368 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 27 May 2019 19:58:15 +0900
Subject: Do not make an incomplete escape a valid char


diff --git a/parse.y b/parse.y
index 24fa3d3..580b3c7 100644
--- a/parse.y
+++ b/parse.y
@@ -6211,7 +6211,7 @@ tokadd_utf8(struct parser_params *p, rb_encoding **encp, https://github.com/ruby/ruby/blob/trunk/parse.y#L6211
 
 	if (c != close_brace) {
 	  unterminated:
-	    literal_flush(p, p->lex.pcur);
+	    token_flush(p);
 	    yyerror0("unterminated Unicode escape");
 	    return;
 	}
@@ -6221,11 +6221,10 @@ tokadd_utf8(struct parser_params *p, rb_encoding **encp, https://github.com/ruby/ruby/blob/trunk/parse.y#L6221
     }
     else {			/* handle \uxxxx form */
 	if (!tokadd_codepoint(p, encp, regexp_literal, FALSE)) {
+	    token_flush(p);
 	    return;
 	}
     }
-
-    return;
 }
 
 #define ESCAPE_CONTROL 1
@@ -6312,7 +6311,7 @@ read_escape(struct parser_params *p, int flags, rb_encoding **encp) https://github.com/ruby/ruby/blob/trunk/parse.y#L6311
       eof:
       case -1:
         yyerror0("Invalid escape character syntax");
-	pushback(p, c);
+	token_flush(p);
 	return '\0';
 
       default:
@@ -6391,6 +6390,7 @@ tokadd_escape(struct parser_params *p, rb_encoding **encp) https://github.com/ruby/ruby/blob/trunk/parse.y#L6390
       eof:
       case -1:
         yyerror0("Invalid escape character syntax");
+	token_flush(p);
 	return -1;
 
       default:
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index b46fcb5..727e967 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -938,7 +938,7 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_scanner_events.rb#L938
 
     assert_equal ["?\\M-H"], scan('CHAR', '?\\M-H')
     err = nil
-    assert_equal ["?\\M"], scan('CHAR', '?\\M ') {|*e| err = e}
+    assert_equal [], scan('CHAR', '?\\M ') {|*e| err = e}
     assert_equal([:on_parse_error, "Invalid escape character syntax", "?\\M "], err)
   end
 
-- 
cgit v0.10.2


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

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