[Bug #19539] Match heredoc identifier from end of line
Not to ignore leading spaces in indented heredoc identifier.
This commit is contained in:
parent
e8e7ff1333
commit
67dd52d59c
Notes:
git
2023-03-18 17:45:36 +00:00
20
parse.y
20
parse.y
@ -8200,19 +8200,19 @@ parser_dedent_string(VALUE self, VALUE input, VALUE width)
|
|||||||
static int
|
static int
|
||||||
whole_match_p(struct parser_params *p, const char *eos, long len, int indent)
|
whole_match_p(struct parser_params *p, const char *eos, long len, int indent)
|
||||||
{
|
{
|
||||||
const char *ptr = p->lex.pbeg;
|
const char *beg = p->lex.pbeg;
|
||||||
long n;
|
const char *ptr = p->lex.pend;
|
||||||
|
|
||||||
|
if (ptr - beg < len) return FALSE;
|
||||||
|
if (ptr > beg && ptr[-1] == '\n') {
|
||||||
|
if (--ptr > beg && ptr[-1] == '\r') --ptr;
|
||||||
|
if (ptr - beg < len) return FALSE;
|
||||||
|
}
|
||||||
|
if (strncmp(eos, ptr -= len, len)) return FALSE;
|
||||||
if (indent) {
|
if (indent) {
|
||||||
while (*ptr && ISSPACE(*ptr)) ptr++;
|
while (beg < ptr && ISSPACE(*beg)) beg++;
|
||||||
}
|
}
|
||||||
n = p->lex.pend - (ptr + len);
|
return beg == ptr;
|
||||||
if (n < 0) return FALSE;
|
|
||||||
if (n > 0 && ptr[len] != '\n') {
|
|
||||||
if (ptr[len] != '\r') return FALSE;
|
|
||||||
if (n <= 1 || ptr[len+1] != '\n') return FALSE;
|
|
||||||
}
|
|
||||||
return strncmp(eos, ptr, len) == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -681,6 +681,16 @@ FOO
|
|||||||
eval "x = <<""FOO\r\n1\r\nFOO"
|
eval "x = <<""FOO\r\n1\r\nFOO"
|
||||||
end
|
end
|
||||||
assert_equal("1\n", x)
|
assert_equal("1\n", x)
|
||||||
|
|
||||||
|
assert_nothing_raised do
|
||||||
|
x = eval "<<' FOO'\n""[Bug #19539]\n"" FOO\n"
|
||||||
|
end
|
||||||
|
assert_equal("[Bug #19539]\n", x)
|
||||||
|
|
||||||
|
assert_nothing_raised do
|
||||||
|
x = eval "<<-' FOO'\n""[Bug #19539]\n"" FOO\n"
|
||||||
|
end
|
||||||
|
assert_equal("[Bug #19539]\n", x)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_magic_comment
|
def test_magic_comment
|
||||||
|
Loading…
x
Reference in New Issue
Block a user