diff --git a/ChangeLog b/ChangeLog index fd03ceca06..7830b4cfd2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Dec 6 17:29:03 2012 Nobuyoshi Nakada + + * parse.y (parser_here_document): flush string content between new + line and :string_embexpr. [ruby-core:48703] [Bug #7255] + Thu Dec 6 16:35:21 2012 Eric Hodel * test/rake/helper.rb: Load envutil correctly. Removed useless rescue diff --git a/parse.y b/parse.y index 622f37c1bd..d2b6f94c78 100644 --- a/parse.y +++ b/parse.y @@ -6107,6 +6107,25 @@ parser_tokadd_string(struct parser_params *parser, #define NEW_STRTERM(func, term, paren) \ rb_node_newnode(NODE_STRTERM, (func), (term) | ((paren) << (CHAR_BIT * 2)), 0) +#ifdef RIPPER +static void +ripper_flush_string_content(struct parser_params *parser, rb_encoding *enc) +{ + if (!NIL_P(parser->delayed)) { + ptrdiff_t len = lex_p - parser->tokp; + if (len > 0) { + rb_enc_str_buf_cat(parser->delayed, parser->tokp, len, enc); + } + ripper_dispatch_delayed_token(parser, tSTRING_CONTENT); + parser->tokp = lex_p; + } +} + +#define flush_string_content(enc) ripper_flush_string_content(parser, (enc)) +#else +#define flush_string_content(enc) ((void)(enc)) +#endif + static int parser_parse_string(struct parser_params *parser, NODE *quote) { @@ -6166,17 +6185,7 @@ parser_parse_string(struct parser_params *parser, NODE *quote) tokfix(); set_yylval_str(STR_NEW3(tok(), toklen(), enc, func)); - -#ifdef RIPPER - if (!NIL_P(parser->delayed)) { - ptrdiff_t len = lex_p - parser->tokp; - if (len > 0) { - rb_enc_str_buf_cat(parser->delayed, parser->tokp, len, enc); - } - ripper_dispatch_delayed_token(parser, tSTRING_CONTENT); - parser->tokp = lex_p; - } -#endif + flush_string_content(enc); return tSTRING_CONTENT; } @@ -6382,6 +6391,7 @@ parser_here_document(struct parser_params *parser, NODE *here) } if (c != '\n') { set_yylval_str(STR_NEW3(tok(), toklen(), enc, func)); + flush_string_content(enc); return tSTRING_CONTENT; } tokadd(nextc()); diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb index c1b72c27f7..7186df3971 100644 --- a/test/ripper/test_scanner_events.rb +++ b/test/ripper/test_scanner_events.rb @@ -676,6 +676,13 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase scan('tstring_content', "<<""EOS\nhere\ndoc \nEOS \n") assert_equal ["heredoc\n\tEOS \n"], scan('tstring_content', "<<""-EOS\nheredoc\n\tEOS \n") + bug7255 = '[ruby-core:48703]' + assert_equal ["there\n""heredoc", "\n"], + scan('tstring_content', "<<""EOS\n""there\n""heredoc\#{foo}\nEOS"), + bug7255 + assert_equal ["there\n""heredoc", "\n"], + scan('tstring_content', "<<""EOS\n""there\n""heredoc\#@foo\nEOS"), + bug7255 end def test_heredoc_end