зеркало из https://github.com/github/ruby.git
Fix interpolated heredoc
This fixes https://bugs.ruby-lang.org/issues/18038. The provided reproduction showed that this happens in heredocs with double interpolation. In this case `DSTR` was getting returned but needs to be convered to a `EVSTR` which is what is returned by the function. There may be an additional bug here that we weren't able to produce. It seems odd that `STR` returns `DSTR` while everything else should return `EVSTR` since the function is `new_evstr`. [Bug #18038][ruby-core:104597] Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
This commit is contained in:
Родитель
fa308a683d
Коммит
b940a45357
5
parse.y
5
parse.y
|
@ -10181,7 +10181,10 @@ new_evstr(struct parser_params *p, NODE *node, const YYLTYPE *loc)
|
||||||
switch (nd_type(node)) {
|
switch (nd_type(node)) {
|
||||||
case NODE_STR:
|
case NODE_STR:
|
||||||
nd_set_type(node, NODE_DSTR);
|
nd_set_type(node, NODE_DSTR);
|
||||||
case NODE_DSTR: case NODE_EVSTR:
|
return node;
|
||||||
|
case NODE_DSTR:
|
||||||
|
break;
|
||||||
|
case NODE_EVSTR:
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1080,6 +1080,32 @@ x = __ENCODING__
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_heredoc_interpolation
|
||||||
|
var = 1
|
||||||
|
|
||||||
|
v1 = <<~HEREDOC
|
||||||
|
something
|
||||||
|
#{"/#{var}"}
|
||||||
|
HEREDOC
|
||||||
|
|
||||||
|
v2 = <<~HEREDOC
|
||||||
|
something
|
||||||
|
#{other = "/#{var}"}
|
||||||
|
HEREDOC
|
||||||
|
|
||||||
|
v3 = <<~HEREDOC
|
||||||
|
something
|
||||||
|
#{("/#{var}")}
|
||||||
|
HEREDOC
|
||||||
|
|
||||||
|
assert_equal "something\n/1\n", v1
|
||||||
|
assert_equal "something\n/1\n", v2
|
||||||
|
assert_equal "something\n/1\n", v3
|
||||||
|
assert_equal v1, v2
|
||||||
|
assert_equal v2, v3
|
||||||
|
assert_equal v1, v3
|
||||||
|
end
|
||||||
|
|
||||||
def test_unexpected_token_error
|
def test_unexpected_token_error
|
||||||
assert_syntax_error('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', /unexpected/)
|
assert_syntax_error('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', /unexpected/)
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче