diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | string.c | 15 |
2 files changed, 21 insertions, 1 deletions
@@ -1,3 +1,7 @@ +Sat Dec 13 18:34:43 2008 Yukihiro Matsumoto <matz@ruby-lang.org> + + * string.c (sym_printable): wrong condition for string iteration. + Sat Dec 13 15:52:27 2008 Yukihiro Matsumoto <matz@ruby-lang.org> * string.c (sym_equal): remove documentation error "Otherwise, @@ -53,6 +57,9 @@ Sat Dec 13 16:04:48 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp> loading a locale encoding on some locale. fixed by Nobuyuki Nakada. + * string.c (sym_inspect): quote if symbol contains non-printable + characters. [ruby-dev:37398] + Sat Dec 13 14:24:38 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp> * test/ruby/enc/test_utf16.rb: feature changed in r20626. @@ -6826,6 +6826,18 @@ sym_equal(VALUE sym1, VALUE sym2) } +static int +sym_printable(const char *s, const char *send, rb_encoding *enc) +{ + while (s < send) { + int c = rb_enc_codepoint(s, send, enc); + int n = rb_enc_codelen(c, enc); + if (!rb_enc_isprint(c, enc)) return Qfalse; + s += n; + } + return Qtrue; +} + /* * call-seq: * sym.inspect => string @@ -6848,7 +6860,8 @@ sym_inspect(VALUE sym) RSTRING_PTR(str)[0] = ':'; memcpy(RSTRING_PTR(str)+1, RSTRING_PTR(sym), RSTRING_LEN(sym)); if (RSTRING_LEN(sym) != strlen(RSTRING_PTR(sym)) || - !rb_enc_symname_p(RSTRING_PTR(sym), enc)) { + !rb_enc_symname_p(RSTRING_PTR(sym), enc) || + !sym_printable(RSTRING_PTR(sym), RSTRING_END(sym), enc)) { str = rb_str_inspect(str); strncpy(RSTRING_PTR(str), ":\"", 2); } |