mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[Bug #18963] Separate string contents by here document terminator
This commit is contained in:
parent
111b69e8a0
commit
ace2eee544
Notes:
git
2022-08-28 11:12:30 +09:00
2 changed files with 23 additions and 0 deletions
13
parse.y
13
parse.y
|
@ -7196,6 +7196,10 @@ tokadd_string(struct parser_params *p,
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
bool erred = false;
|
bool erred = false;
|
||||||
|
#ifdef RIPPER
|
||||||
|
const int heredoc_end = (p->heredoc_end ? p->heredoc_end + 1 : 0);
|
||||||
|
int top_of_line = FALSE;
|
||||||
|
#endif
|
||||||
|
|
||||||
#define mixed_error(enc1, enc2) \
|
#define mixed_error(enc1, enc2) \
|
||||||
(void)(erred || (parser_mixed_error(p, enc1, enc2), erred = true))
|
(void)(erred || (parser_mixed_error(p, enc1, enc2), erred = true))
|
||||||
|
@ -7206,6 +7210,12 @@ tokadd_string(struct parser_params *p,
|
||||||
if (p->heredoc_indent > 0) {
|
if (p->heredoc_indent > 0) {
|
||||||
parser_update_heredoc_indent(p, c);
|
parser_update_heredoc_indent(p, c);
|
||||||
}
|
}
|
||||||
|
#ifdef RIPPER
|
||||||
|
if (top_of_line && heredoc_end == p->ruby_sourceline) {
|
||||||
|
pushback(p, c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (paren && c == paren) {
|
if (paren && c == paren) {
|
||||||
++*nest;
|
++*nest;
|
||||||
|
@ -7332,6 +7342,9 @@ tokadd_string(struct parser_params *p,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tokadd(p, c);
|
tokadd(p, c);
|
||||||
|
#ifdef RIPPER
|
||||||
|
top_of_line = (c == '\n');
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
terminate:
|
terminate:
|
||||||
if (*enc) *encp = *enc;
|
if (*enc) *encp = *enc;
|
||||||
|
|
|
@ -242,4 +242,14 @@ class TestRipper::Lexer < Test::Unit::TestCase
|
||||||
EOF
|
EOF
|
||||||
assert_equal([[5, 0], :on_heredoc_end, "EOS\n", state(:EXPR_BEG)], Ripper.lex(s).last, bug)
|
assert_equal([[5, 0], :on_heredoc_end, "EOS\n", state(:EXPR_BEG)], Ripper.lex(s).last, bug)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_tokenize_with_here_document
|
||||||
|
bug = '[Bug #18963]'
|
||||||
|
code = %[
|
||||||
|
<<A + "hello
|
||||||
|
A
|
||||||
|
world"
|
||||||
|
]
|
||||||
|
assert_equal(code, Ripper.tokenize(code).join(""), bug)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue