From 785521bd5133501c7315c5aace783a8d8ef6b5ac Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 24 Feb 2012 22:54:00 +0000 Subject: [PATCH] * parse.y (parser_tokadd_string): insert a backslash only if quoted by single quotes. [ruby-dev:45281] [Bug #6069] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ parse.y | 3 +-- test/ruby/test_literal.rb | 12 +++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe6dab02b3..f2e68847a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Feb 25 07:53:58 2012 Nobuyoshi Nakada + + * parse.y (parser_tokadd_string): insert a backslash only if + quoted by single quotes. [ruby-dev:45281] [Bug #6069] + Sat Feb 25 07:53:49 2012 Nobuyoshi Nakada * dir.c (dir_inspect), io.c (rb_io_inspect): keep encoding of path. diff --git a/parse.y b/parse.y index 3460c38518..e47dac4304 100644 --- a/parse.y +++ b/parse.y @@ -6507,7 +6507,7 @@ parser_tokadd_string(struct parser_params *parser, default: if (c == -1) return -1; if (!ISASCII(c)) { - tokadd('\\'); + if ((func & STR_FUNC_EXPAND) == 0) tokadd('\\'); goto non_ascii; } if (func & STR_FUNC_REGEXP) { @@ -7597,7 +7597,6 @@ parser_yylex(struct parser_params *parser) } else if (!lex_eol_p() && !(c = *lex_p, ISASCII(c))) { nextc(); - tokadd('\\'); if (tokadd_mbchar(c) == -1) return 0; } else { diff --git a/test/ruby/test_literal.rb b/test/ruby/test_literal.rb index bb3f50d2e5..e7a7c76891 100644 --- a/test/ruby/test_literal.rb +++ b/test/ruby/test_literal.rb @@ -79,9 +79,15 @@ class TestRubyLiteral < Test::Unit::TestCase assert_equal "\x13", "\c\x33" assert_equal "\x13", "\C-\x33" assert_equal "\xB3", "\M-\x33" - assert_equal "\\\u201c", eval(%["\\\u{201c}"]), bug6069 - assert_equal "\\\u201c".encode("euc-jp"), eval(%["\\\u{201c}"].encode("euc-jp")), bug6069 - assert_equal "\\\u201c".encode("iso-8859-13"), eval(%["\\\u{201c}"].encode("iso-8859-13")), bug6069 + assert_equal "\u201c", eval(%["\\\u{201c}"]), bug5262 + assert_equal "\u201c".encode("euc-jp"), eval(%["\\\u{201c}"].encode("euc-jp")), bug5262 + assert_equal "\u201c".encode("iso-8859-13"), eval(%["\\\u{201c}"].encode("iso-8859-13")), bug5262 + assert_equal "\\\u201c", eval(%['\\\u{201c}']), bug6069 + assert_equal "\\\u201c".encode("euc-jp"), eval(%['\\\u{201c}'].encode("euc-jp")), bug6069 + assert_equal "\\\u201c".encode("iso-8859-13"), eval(%['\\\u{201c}'].encode("iso-8859-13")), bug6069 + assert_equal "\u201c", eval(%[?\\\u{201c}]), bug6069 + assert_equal "\u201c".encode("euc-jp"), eval(%[?\\\u{201c}].encode("euc-jp")), bug6069 + assert_equal "\u201c".encode("iso-8859-13"), eval(%[?\\\u{201c}].encode("iso-8859-13")), bug6069 end def test_dstring