mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
75755ef159
commit
d25faa4ed2
2 changed files with 10 additions and 3 deletions
11
parse.y
11
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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue