aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-16 01:27:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-16 01:27:47 +0000
commit248df8637b8914a320178b9eebfaae45baf0e544 (patch)
treebee64ac03c53de81c2490dfb2b2a3f0f53a74226
parentc27920c1a9e8f6aa84caff98b5202baf71c8f957 (diff)
downloadruby-248df8637b8914a320178b9eebfaae45baf0e544.tar.gz
multiline heredoc identifier
* parse.y (parser_heredoc_identifier): reject multiline here document identifier, which never matches single line. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--parse.y11
-rw-r--r--test/ruby/test_syntax.rb2
2 files changed, 10 insertions, 3 deletions
diff --git a/parse.y b/parse.y
index cf05a9c891..daa0fe1f96 100644
--- a/parse.y
+++ b/parse.y
@@ -6434,13 +6434,20 @@ parser_heredoc_identifier(struct parser_params *parser)
while ((c = nextc()) != -1 && c != term) {
if (tokadd_mbchar(c) == -1) return 0;
if (c == '\n') newline = 1;
+ else if (newline) newline = 2;
}
if (c == -1) {
compile_error(PARSER_ARG "unterminated here document identifier");
return 0;
}
- if (newline) {
- rb_warn0("here document identifier contains newline");
+ switch (newline) {
+ case 1:
+ rb_warn0("here document identifier ends with a newline");
+ if (--tokidx > 0 && tokenbuf[tokidx] == '\r') --tokidx;
+ break;
+ case 2:
+ compile_error(PARSER_ARG "here document identifier across newlines, never match");
+ return -1;
}
break;
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index 4c4e840e5e..f3db9bcd48 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -746,7 +746,7 @@ eom
end
def test_heredoc_newline
- assert_warn(/contains newline/) do
+ assert_warn(/ends with a newline/) do
eval("<<\"EOS\n\"\nEOS\n")
end
end