mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (rb_str_inspect): NUL should not be represented as
"\0" when octal digits may follow. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1f4e534815
commit
ade2ba57a2
3 changed files with 16 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Apr 23 09:51:26 2013 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* string.c (rb_str_inspect): NUL should not be represented as
|
||||
"\0" when octal digits may follow.
|
||||
|
||||
Mon Apr 22 22:54:00 2013 Charlie Somerville <charlie@charliesomerville.com>
|
||||
|
||||
* insns.def (opt_mod): Use % operator if both operands are positive for
|
||||
|
|
6
string.c
6
string.c
|
@ -4572,7 +4572,11 @@ rb_str_inspect(VALUE str)
|
|||
}
|
||||
}
|
||||
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;
|
||||
|
|
|
@ -1985,6 +1985,12 @@ class TestString < Test::Unit::TestCase
|
|||
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"))
|
||||
|
|
Loading…
Add table
Reference in a new issue