Project

General

Profile

Actions

Backport #8290

closed

String#inspect should not represent NUL as "\0" when octal digits may follow.

Added by knu (Akinori MUSHA) about 11 years ago. Updated almost 11 years ago.


Description

Starting from Ruby 2.0.0, String#inspect represents the NUL character as "\0" but it is not appropriate at least when octal digits follow.
Not only is it confusing to human eyes but it also breaks the characteristic of String#inspect that you can "eval" the result to get the original string, though not guaranteed.

% ruby -ve 'p "\0"+"12"'

ruby 1.8.7 (2012-10-12 patchlevel 371) [x86_64-freebsd9]

"\00012"
=> OK

ruby 1.9.3p409 (2013-04-04) [x86_64-freebsd9]

"\u000012"
=> OK

ruby 2.0.0p145 (2013-04-17 revision 40339) [x86_64-freebsd9]

"\012"
=> Confusing

ruby 2.1.0dev (2013-04-19 trunk 40366) [x86_64-freebsd9]

"\012"
=> Confusing

Attached is a patch that fixes this issue.


Files

Actions #1

Updated by knu (Akinori MUSHA) almost 11 years ago

  • % Done changed from 0 to 100
  • Status changed from Open to Closed

This issue was solved with changeset r40414.
Akinori, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


Add references.

  • string.c (rb_str_inspect): NUL should not be represented as "\0"
    when octal digits may follow. [ruby-core:54458] [Bug #8290]
Actions #2

Updated by naruse (Yui NARUSE) almost 11 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby master to Backport200
  • Category deleted (core)
  • Status changed from Closed to Assigned
  • Target version deleted (2.6)

Updated by nagachika (Tomoyuki Chikanaga) almost 11 years ago

  • Assignee set to nagachika (Tomoyuki Chikanaga)
Actions #4

Updated by nagachika (Tomoyuki Chikanaga) almost 11 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r40488.
Akinori, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 40413,40414,40415,40423: [Backport #8290]

* string.c (rb_str_inspect): NUL should not be represented as
  "\0" when octal digits may follow.

* string.c (rb_str_inspect): NUL should not be represented as "\0"
  when octal digits may follow.  [ruby-core:54458] [Bug #8290]

* test/ruby/test_module.rb
  (TestModule#test_const_get_invalid_name)
  (test_const_defined_invalid_name): Fix expected values.

* string.c (rb_str_inspect): refix r40413, on Ruby 1.9 usual character
  escape uses hex/Unicode escapes, so fix to use Unicode escape on
  Unicode strings and hex on others. [ruby-core:54458] [Bug #8290]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0