Commit 3a2ff982 authored by Seeker's avatar Seeker

Fix for empty lines in squiggly heredocs

parent 6d98ae57
......@@ -1362,26 +1362,29 @@ heredoc_end(parser_state *p)
node *pair = list->car->cdr;
const char *str = (char*)pair->car;
size_t len = (size_t)pair->cdr;
if (counting) {
list2 = push(list2, pair);
}
mrb_bool check = counting;
mrb_bool empty = TRUE;
mrb_bool newline = FALSE;
size_t spaces = 0;
for (size_t i = 0; i < len; i++) {
if (counting) {
if (str[i] == '\n') {
counting = TRUE;
newline = TRUE;
break;
}
if (ISSPACE(str[i])) {
if (counting)
++spaces;
}
else {
counting = FALSE;
if (indent == -1 || spaces < indent) {
indent = spaces;
}
empty = FALSE;
}
}
if (str[i] == '\n') {
counting = TRUE;
break;
}
if (check) {
if ((indent == -1 || spaces < indent) && (!empty || !newline))
indent = spaces;
list2 = push(list2, cons((node*)spaces, pair));
}
}
else {
......@@ -1391,11 +1394,15 @@ heredoc_end(parser_state *p)
}
if (indent > 0) {
while (list2) {
node *pair = list2->car;
node *n = list2->car;
size_t spaces = (size_t)n->car;
if (spaces >= indent) {
node *pair = n->cdr;
const char *str = (char*)pair->car;
size_t len = (size_t)pair->cdr;
pair->car = (node*)(str + indent);
pair->cdr = (node*)(len - indent);
}
list2 = list2->cdr;
}
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -181,6 +181,12 @@ QQ2
UUU2
u#{3}u
UUU3
v = <<~VVV
\tvvv
\t\t
\t#{123}
VVV
w = %W( 1 #{<<WWW} 3
www
......@@ -221,6 +227,7 @@ ZZZ
assert_equal "sss\n sss\n", s
assert_equal "ttt\n ttt\n", t
assert_equal ["u1u\n", "u2u\n", "u\#{3}u\n"], u
assert_equal "\nvvv\n\t\n123\n", v
assert_equal ["1", "www\n", "3", "4", "5"], w
assert_equal [1, "foo 222 333\n 444\n5\n bar\n6\n", 9], x
assert_equal "", z
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment