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 about 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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0