summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUKUZAWA-Tadashi <[email protected]>2013-03-17 21:22:21 +0900
committerMasaki Muranaka <[email protected]>2013-03-19 11:03:08 +0900
commit801bc9e39e33c0ae0f76a1ffd08605d95c1dc7da (patch)
treeef9722b6a8666f895755b076c8a866065448337e
parente5a66685b04cc5550c1faaa0fd5fbcdba1280701 (diff)
downloadmruby-801bc9e39e33c0ae0f76a1ffd08605d95c1dc7da.tar.gz
mruby-801bc9e39e33c0ae0f76a1ffd08605d95c1dc7da.zip
bugfix about escaping '\n'
-rw-r--r--src/parse.y26
-rw-r--r--test/t/literals.rb18
2 files changed, 34 insertions, 10 deletions
diff --git a/src/parse.y b/src/parse.y
index 21823451b..bfbdd9eb1 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -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;
@@ -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));
@@ -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);
@@ -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 {
@@ -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) {
diff --git a/test/t/literals.rb b/test/t/literals.rb
index 5dc15f135..5a29cff0c 100644
--- a/test/t/literals.rb
+++ b/test/t/literals.rb
@@ -140,6 +140,11 @@ assert('Literals Array', '8.7.6.4') do
#{-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
@@ -147,7 +152,8 @@ assert('Literals Array', '8.7.6.4') do
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}
@@ -161,6 +167,11 @@ assert('Literals Array', '8.7.6.4') do
#{-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
@@ -168,8 +179,9 @@ assert('Literals Array', '8.7.6.4') do
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