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

ruby-changes:55615

From: Nobuyoshi <ko1@a...>
Date: Mon, 29 Apr 2019 15:12:58 +0900 (JST)
Subject: [ruby-changes:55615] Nobuyoshi Nakada:1432471a75 (trunk): Disallow also CR in here-doc identifier

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

From 1432471a759dc0cbc80c53766894dba45e6da887 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 29 Apr 2019 13:45:32 +0900
Subject: Disallow also CR in here-doc identifier

* parse.y (heredoc_identifier): CR in here-document identifier
  might or might not result in a syntax error, by the EOL code.
  make a syntax error regardless of the EOL code.

diff --git a/doc/syntax/literals.rdoc b/doc/syntax/literals.rdoc
index 00bc4f8..35a2f01 100644
--- a/doc/syntax/literals.rdoc
+++ b/doc/syntax/literals.rdoc
@@ -256,7 +256,7 @@ behaves like Kernel#`: https://github.com/ruby/ruby/blob/trunk/doc/syntax/literals.rdoc#L256
   HEREDOC
 
 When surrounding with quotes, any characters but that quote and newline
-can be used as the identifier.
+(CR and/or LF) can be used as the identifier.
 
 To call a method on a heredoc place it after the opening identifier:
 
diff --git a/parse.y b/parse.y
index fddd02a..3c52f5b 100644
--- a/parse.y
+++ b/parse.y
@@ -6820,7 +6820,7 @@ heredoc_identifier(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L6820
 	tokadd(p, func);
 	term = c;
 	while ((c = nextc(p)) != -1 && c != term) {
-	    if (c == '\n') goto unterminated;
+	    if (c == '\r' || c == '\n') goto unterminated;
 	    if (tokadd_mbchar(p, c) == -1) return 0;
 	}
 	if (c == -1) {
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index 66adeb1..7717647 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -857,6 +857,12 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L857
     assert_syntax_error("<<\"EOS\n\"\nEOS\n", /unterminated/)
   end
 
+  def test_unterminated_heredoc_cr
+    %W[\r\n \n].each do |nl|
+      assert_syntax_error("<<\"\r\"#{nl}\r#{nl}", /unterminated/, nil, "CR with #{nl.inspect}")
+    end
+  end
+
   def test__END___cr
     assert_syntax_error("__END__\r<<<<<\n", /unexpected <</)
   end
-- 
cgit v0.10.2


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

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