mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (rb_str_inspect): escape ASCII-compatible strings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28051 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
11cef3cca3
commit
2138c773cc
3 changed files with 13 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
Fri May 28 18:37:04 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_inspect): escape ASCII-compatible strings.
|
||||
|
||||
Fri May 28 17:34:48 2010 URABE Shyouhei <shyouhei@ruby-lang.org>
|
||||
|
||||
* array.c (rb_ary_product): Use tmpary instead, to ensure marking
|
||||
|
|
3
string.c
3
string.c
|
@ -4100,6 +4100,7 @@ rb_str_inspect(VALUE str)
|
|||
VALUE result = rb_str_buf_new(0);
|
||||
rb_encoding *resenc = rb_default_internal_encoding();
|
||||
int unicode_p = rb_enc_unicode_p(enc);
|
||||
int asciicompat = rb_enc_asciicompat(enc);
|
||||
|
||||
if (resenc == NULL) resenc = rb_default_external_encoding();
|
||||
if (!rb_enc_asciicompat(resenc)) resenc = rb_usascii_encoding();
|
||||
|
@ -4159,7 +4160,7 @@ rb_str_inspect(VALUE str)
|
|||
continue;
|
||||
}
|
||||
if ((enc == resenc && rb_enc_isprint(c, enc)) ||
|
||||
(rb_enc_isascii(c, enc) && ISPRINT(c))) {
|
||||
(asciicompat && rb_enc_isascii(c, enc) && ISPRINT(c))) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -1874,4 +1874,11 @@ class TestString < Test::Unit::TestCase
|
|||
assert_equal(s, k, '[ruby-dev:39068]')
|
||||
assert_equal(Encoding::UTF_8, k.encoding, '[ruby-dev:39068]')
|
||||
end
|
||||
|
||||
def test_ascii_incomat_inspect
|
||||
[Encoding::UTF_16LE, Encoding::UTF_16BE,
|
||||
Encoding::UTF_32LE, Encoding::UTF_32BE].each do |e|
|
||||
assert_equal('"\\u0061\\u0062\\u0063"', "abc".encode(e).inspect)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue