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:
parent
23375c8b81
commit
1432471a75
3 changed files with 8 additions and 2 deletions
|
@ -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:
|
||||
|
||||
|
|
2
parse.y
2
parse.y
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue