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.
This commit is contained in:
Nobuyoshi Nakada 2019-04-29 13:45:32 +09:00
parent 23375c8b81
commit 1432471a75
No known key found for this signature in database
GPG Key ID: 4BC7D6DF58D8DF60
3 changed files with 8 additions and 2 deletions

View File

@ -256,7 +256,7 @@ behaves like Kernel#`:
HEREDOC HEREDOC
When surrounding with quotes, any characters but that quote and newline 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: To call a method on a heredoc place it after the opening identifier:

View File

@ -6820,7 +6820,7 @@ heredoc_identifier(struct parser_params *p)
tokadd(p, func); tokadd(p, func);
term = c; term = c;
while ((c = nextc(p)) != -1 && c != term) { 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 (tokadd_mbchar(p, c) == -1) return 0;
} }
if (c == -1) { if (c == -1) {

View File

@ -857,6 +857,12 @@ eom
assert_syntax_error("<<\"EOS\n\"\nEOS\n", /unterminated/) assert_syntax_error("<<\"EOS\n\"\nEOS\n", /unterminated/)
end 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 def test__END___cr
assert_syntax_error("__END__\r<<<<<\n", /unexpected <</) assert_syntax_error("__END__\r<<<<<\n", /unexpected <</)
end end