Skip to content

Commit

Permalink
bugfix about escaping '\n'
Browse files Browse the repository at this point in the history
  • Loading branch information
FUKUZAWA-Tadashi committed Mar 17, 2013
1 parent 4169810 commit 76c2489
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
26 changes: 19 additions & 7 deletions src/parse.y
Expand Up @@ -3535,7 +3535,7 @@ parse_string(parser_state *p)
char buf[256];
snprintf(buf, sizeof(buf), "can't find string \"%s\" anywhere before EOF", hinf->term);
yyerror(p, buf);
return 0;
return 0;
}
yylval.nd = new_str(p, tok(p), toklen(p));
return tSTRING_MID;
Expand All @@ -3558,6 +3558,11 @@ parse_string(parser_state *p)
if (c == end || c == beg) {
tokadd(p, c);
}
else if ((c == '\n') && (type & STR_FUNC_ARRAY)) {
p->lineno++;
p->column = 0;
tokadd(p, '\n');
}
else {
pushback(p, c);
tokadd(p, read_escape(p));
Expand All @@ -3570,14 +3575,14 @@ parse_string(parser_state *p)
case '\n':
p->lineno++;
p->column = 0;
continue;
break;

case '\\':
c = '\\';
break;

default:
tokadd(p, '\\');
if (! ISSPACE(c))
tokadd(p, '\\');
}
}
tokadd(p, c);
Expand All @@ -3601,7 +3606,12 @@ parse_string(parser_state *p)
}
if ((type & STR_FUNC_ARRAY) && ISSPACE(c)) {
if (toklen(p) == 0) {
do {} while (ISSPACE(c = nextc(p)));
do {
if (c == '\n') {
p->lineno++;
p->column = 0;
}
} while (ISSPACE(c = nextc(p)));
pushback(p, c);
return tLITERAL_DELIM;
} else {
Expand Down Expand Up @@ -3681,8 +3691,10 @@ heredoc_identifier(parser_state *p)
quote = TRUE;
newtok(p);
while ((c = nextc(p)) != -1 && c != term) {
if (c == '\n')
c = -1;
if (c == '\n') {
c = -1;
break;
}
tokadd(p, c);
}
if (c == -1) {
Expand Down
18 changes: 15 additions & 3 deletions test/t/literals.rb
Expand Up @@ -140,14 +140,20 @@
#{-1}1
2#{2}
}
h = %W(a\nb
test\ abc
c\
d
x\y x\\y x\\\y)

test1 = (a == ['abc3def', '}g'] and
b == ['abc', '5', 'def', '(g'] and
c == ['7'] and
d == ['9'] and
e == [] and
f == ['[ab', 'cd][ef]'] and
g == ['ab', '-11', '22']
g == ['ab', '-11', '22'] and
h == ["a\nb", 'test abc', "c\nd", "xy", "x\\y", "x\\y"]
)

a = %w{abc#{1+2}def \}g}
Expand All @@ -161,15 +167,21 @@
#{-1}1
2#{2}
}
h = %w(a\nb
test\ abc
c\
d
x\y x\\y x\\\y)

test2 = (a == ['abc#{1+2}def', '}g'] and
b == ['abc', '#{2+3}', 'def', '(g'] and
c == ['#{3+4}'] and
d == ['#{4+5}'] and
e == [] and
f == ['[ab', 'cd][ef]'] and
g == ['ab', '#{-1}1', '2#{2}']
)
g == ['ab', '#{-1}1', '2#{2}'] and
h == ["a\\nb", "test abc", "c\nd", "x\\y", "x\\y", "x\\\\y"]
)

test1 and test2
end
Expand Down

0 comments on commit 76c2489

Please sign in to comment.