Project

General

Profile

Backport #8290 ยป 0001-string.c-rb_str_inspect-NUL-should-not-be-represente.patch

knu (Akinori MUSHA), 04/19/2013 03:51 PM

View differences:

ChangeLog
Fri Apr 19 15:15:14 2013 Akinori MUSHA <knu@iDaemons.org>
* string.c (rb_str_inspect): NUL should not be represented as
"\0" when octal digits may follow.
Fri Apr 19 13:03:14 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* marshal.c (w_object): do not dump encoding which is dumped with
string.c
}
}
switch (c) {
case '\0': cc = '0'; break;
case '\0':
if (p - n > prev) str_buf_cat(result, prev, p - n - prev);
str_buf_cat(result, "\\000", 4);
prev = p;
continue;
case '\n': cc = 'n'; break;
case '\r': cc = 'r'; break;
case '\t': cc = 't'; break;
test/ruby/test_string.rb
assert_instance_of(String, s.to_s)
end
def test_inspect_nul
s = "\0" + "12"
assert_not_equal '"\\012"', eval(s.inspect)
assert_equal s, eval(s.inspect)
end
def test_partition
assert_equal(%w(he l lo), "hello".partition(/l/))
assert_equal(%w(he l lo), "hello".partition("l"))
    (1-1/1)