aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--parse.y9
-rw-r--r--test/ripper/test_sexp.rb3
3 files changed, 13 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 9e497c2f2a..a275a5efa3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Tue Dec 2 06:31:31 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Dec 2 06:32:02 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (ripper_flush_string_content): preserve the dispatched
+ results at tSTRING_CONTENT. [ruby-dev:48714] [Bug #10437]
* parse.y (regexp_contents): check in ripper only if the whole
content is a single regexp without interpolation.
diff --git a/parse.y b/parse.y
index a50047eeb5..13a0f480ec 100644
--- a/parse.y
+++ b/parse.y
@@ -6302,6 +6302,8 @@ static void
ripper_flush_string_content(struct parser_params *parser, rb_encoding *enc)
{
VALUE content = yylval.val;
+ if (!ripper_is_node_yylval(content))
+ content = ripper_new_yylval(0, 0, content);
if (!NIL_P(parser->delayed)) {
ptrdiff_t len = lex_p - parser->tokp;
if (len > 0) {
@@ -6309,11 +6311,12 @@ ripper_flush_string_content(struct parser_params *parser, rb_encoding *enc)
}
ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
parser->tokp = lex_p;
+ RNODE(content)->nd_rval = yylval.val;
}
- if (!ripper_is_node_yylval(content))
- content = ripper_new_yylval(0, 0, content);
- yylval.val = content;
ripper_dispatch_scan_event(parser, tSTRING_CONTENT);
+ if (yylval.val != content)
+ RNODE(content)->nd_rval = yylval.val;
+ yylval.val = content;
}
#define flush_string_content(enc) ripper_flush_string_content(parser, (enc))
diff --git a/test/ripper/test_sexp.rb b/test/ripper/test_sexp.rb
index adf8c46ec7..2c5bcdacde 100644
--- a/test/ripper/test_sexp.rb
+++ b/test/ripper/test_sexp.rb
@@ -26,6 +26,9 @@ class TestRipper::Sexp < Test::Unit::TestCase
sexp = Ripper.sexp('/foo/')
assert_equal 'foo', search_sexp(:@tstring_content, search_sexp(:regexp_literal, sexp))[1]
+ sexp = Ripper.sexp("/foo\nbar/")
+ assert_equal "foo\nbar", search_sexp(:@tstring_content, search_sexp(:regexp_literal, sexp))[1]
+
sexp = Ripper.sexp('/(?<n>a(b|\g<n>))/')
assert_equal '(?<n>a(b|\g<n>))', search_sexp(:@tstring_content, search_sexp(:regexp_literal, sexp))[1]
end