1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
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:

View file

@ -6820,7 +6820,7 @@ heredoc_identifier(struct parser_params *p)
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) {

View file

@ -857,6 +857,12 @@ eom
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