diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-14 02:35:51 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-14 02:35:51 +0000 |
commit | c05fa459bb9f77c4fecdd230e8d1379cc997975e (patch) | |
tree | 6150004feae5cbc52d874119c7b61362b490100b | |
parent | 251c7892c15082078b8db3607155b262ad8ea490 (diff) | |
download | ruby-c05fa459bb9f77c4fecdd230e8d1379cc997975e.tar.gz |
quote symbols
* sprintf.c (ruby__sfvextra): quote symbols as identifiers.
* string.c (rb_id_quote_unprintable): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | sprintf.c | 6 | ||||
-rw-r--r-- | string.c | 8 | ||||
-rw-r--r-- | test/-ext-/test_printf.rb | 2 |
3 files changed, 14 insertions, 2 deletions
@@ -1378,6 +1378,12 @@ ruby__sfvextra(rb_printf_buffer *fp, size_t valsize, void *valp, long *sz, int s } value = rb_inspect(value); } + else if (SYMBOL_P(value)) { + value = rb_sym2str(value); + if (sign == ' ' && !rb_str_symname_p(value)) { + value = rb_str_inspect(value); + } + } else { value = rb_obj_as_string(value); if (sign == ' ') value = QUOTE(value); @@ -10364,7 +10364,7 @@ rb_str_symname_p(VALUE sym) ptr = RSTRING_PTR(sym); len = RSTRING_LEN(sym); if ((resenc != enc && !rb_str_is_ascii_only_p(sym)) || len != (long)strlen(ptr) || - !rb_enc_symname_p(ptr, enc) || !sym_printable(ptr, ptr + len, enc)) { + !rb_enc_symname2_p(ptr, len, enc) || !sym_printable(ptr, ptr + len, enc)) { return FALSE; } return TRUE; @@ -10394,7 +10394,11 @@ rb_str_quote_unprintable(VALUE str) MJIT_FUNC_EXPORTED VALUE rb_id_quote_unprintable(ID id) { - return rb_str_quote_unprintable(rb_id2str(id)); + VALUE str = rb_id2str(id); + if (!rb_str_symname_p(str)) { + return rb_str_inspect(str); + } + return str; } /* diff --git a/test/-ext-/test_printf.rb b/test/-ext-/test_printf.rb index cd3ba76364..feaeadd975 100644 --- a/test/-ext-/test_printf.rb +++ b/test/-ext-/test_printf.rb @@ -24,6 +24,8 @@ class Test_SPrintf < Test::Unit::TestCase assert_equal('["\n"]', Bug::Printf.q("\n")) assert_equal('[aaa]', Bug::Printf.q('aaa')) assert_equal('[a a]', Bug::Printf.q('a a')) + assert_equal('[]', Bug::Printf.q('')) + assert_equal('[""]', Bug::Printf.q(:'')) end def test_encoding |