mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: newline in heredoc identifier
* parse.y (parser_heredoc_identifier): warn newline in here document identifier. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
def2a2cb3f
commit
2d6538a7c8
2 changed files with 11 additions and 0 deletions
5
parse.y
5
parse.y
|
@ -6406,6 +6406,7 @@ parser_heredoc_identifier(struct parser_params *parser)
|
||||||
int c = nextc(), term, func = 0;
|
int c = nextc(), term, func = 0;
|
||||||
int token = tSTRING_BEG;
|
int token = tSTRING_BEG;
|
||||||
long len;
|
long len;
|
||||||
|
int newline = 0;
|
||||||
|
|
||||||
if (c == '-') {
|
if (c == '-') {
|
||||||
c = nextc();
|
c = nextc();
|
||||||
|
@ -6432,11 +6433,15 @@ parser_heredoc_identifier(struct parser_params *parser)
|
||||||
term = c;
|
term = c;
|
||||||
while ((c = nextc()) != -1 && c != term) {
|
while ((c = nextc()) != -1 && c != term) {
|
||||||
if (tokadd_mbchar(c) == -1) return 0;
|
if (tokadd_mbchar(c) == -1) return 0;
|
||||||
|
if (c == '\n') newline = 1;
|
||||||
}
|
}
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
compile_error(PARSER_ARG "unterminated here document identifier");
|
compile_error(PARSER_ARG "unterminated here document identifier");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (newline) {
|
||||||
|
rb_warn0("here document identifier contains newline");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -745,6 +745,12 @@ eom
|
||||||
assert_syntax_error("puts <<""EOS\n""ng\n""EOS\r""NO\n", /can't find string "EOS" anywhere before EOF/)
|
assert_syntax_error("puts <<""EOS\n""ng\n""EOS\r""NO\n", /can't find string "EOS" anywhere before EOF/)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_heredoc_newline
|
||||||
|
assert_warn(/contains newline/) do
|
||||||
|
eval("<<\"EOS\n\"\nEOS\n")
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in a new issue