summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-04-29 00:24:26 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-04-29 12:49:59 +0900
commit330b376133e00ae418bcf01e641e127df01fbc28 (patch)
treedb843d9f0afd5d6334b422fcc5a48aee38ae14ce /parse.y
parent69cad44facc4dedfe181c6a669b63fb9da2aa673 (diff)
parse.y: fix here-doc identifier with newline
* parse.y (heredoc_identifier): quoted here-document identifier must end within the same line. the only corner case that here-document identifier can contain a newline is that the closing qoute is placed at the beginning of the next line, and has been warned since 2.4. ```ruby <<"EOS " # warning: here document identifier ends with a newline EOS ```
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y14
1 files changed, 2 insertions, 12 deletions
diff --git a/parse.y b/parse.y
index 7c5e8c3772..fddd02a9b3 100644
--- a/parse.y
+++ b/parse.y
@@ -6788,7 +6788,6 @@ heredoc_identifier(struct parser_params *p)
int c = nextc(p), term, func = 0, term_len = 2;
enum yytokentype token = tSTRING_BEG;
long len;
- int newline = 0;
int indent = 0;
if (c == '-') {
@@ -6821,23 +6820,14 @@ heredoc_identifier(struct parser_params *p)
tokadd(p, func);
term = c;
while ((c = nextc(p)) != -1 && c != term) {
+ if (c == '\n') goto unterminated;
if (tokadd_mbchar(p, c) == -1) return 0;
- if (!newline && c == '\n') newline = 1;
- else if (newline) newline = 2;
}
if (c == -1) {
+ unterminated:
yyerror(NULL, p, "unterminated here document identifier");
return -1;
}
- switch (newline) {
- case 1:
- rb_warn0("here document identifier ends with a newline");
- if (--p->tokidx > 0 && p->tokenbuf[p->tokidx] == '\r') --p->tokidx;
- break;
- case 2:
- compile_error(p, "here document identifier across newlines, never match");
- return -1;
- }
break;
default: