Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mrbgems/mruby-bin-debugger/bintest/print.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def m

tc << {:cmd=>'p "str"', :exp=>'$1 = "str"'}
tc << {:cmd=>'p "s\tt\rr\n"', :exp=>'$2 = "s\\tt\\rr\\n"'}
tc << {:cmd=>'p "\C-a\C-z"', :exp=>'$3 = "\\x01\\x1a"'}
tc << {:cmd=>'p "\C-a\C-z"', :exp=>'$3 = "\\x01\\x1A"'}
tc << {:cmd=>'p "#{foo+bar}"', :exp=>'$4 = "foobar"'}

tc << {:cmd=>'p \'str\'', :exp=>'$5 = "str"'}
Expand All @@ -381,12 +381,12 @@ def m

tc << {:cmd=>'p %!str!', :exp=>'$9 = "str"'}
tc << {:cmd=>'p %!s\tt\rr\n!', :exp=>'$10 = "s\\tt\\rr\\n"'}
tc << {:cmd=>'p %!\C-a\C-z!', :exp=>'$11 = "\\x01\\x1a"'}
tc << {:cmd=>'p %!\C-a\C-z!', :exp=>'$11 = "\\x01\\x1A"'}
tc << {:cmd=>'p %!#{foo+bar}!', :exp=>'$12 = "foobar"'}

tc << {:cmd=>'p %Q!str!', :exp=>'$13 = "str"'}
tc << {:cmd=>'p %Q!s\tt\rr\n!', :exp=>'$14 = "s\\tt\\rr\\n"'}
tc << {:cmd=>'p %Q!\C-a\C-z!', :exp=>'$15 = "\\x01\\x1a"'}
tc << {:cmd=>'p %Q!\C-a\C-z!', :exp=>'$15 = "\\x01\\x1A"'}
tc << {:cmd=>'p %Q!#{foo+bar}!', :exp=>'$16 = "foobar"'}

tc << {:cmd=>'p %q!str!', :exp=>'$17 = "str"'}
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-encoding/test/numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
assert_equal [171], s.codepoints
assert_equal 171, s.ord
assert_equal [171], s.scrub.bytes
assert_equal "\"\\xab\"", s.inspect
assert_equal "\"\\xAB\"", s.inspect
assert_equal Encoding::BINARY, s.encoding
assert_true s.valid_encoding?
assert_equal Encoding::BINARY, s.dup.encoding
Expand Down
4 changes: 2 additions & 2 deletions mrbgems/mruby-string-ext/test/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def assert_upto(exp, receiver, *args)
assert('String#dump') do
assert_equal("\"\\x00\"", "\0".dump)
assert_equal("\"foo\"", "foo".dump)
assert_equal('"\xe3\x82\x8b"', "る".dump)
assert_equal('"\xE3\x82\x8B"', "る".dump)
assert_nothing_raised { ("\1" * 100).dump } # regress #1210
end

Expand All @@ -21,7 +21,7 @@ def assert_upto(exp, receiver, *args)
# which a string holding no characters has nothing to gain from. `dump` on
# the same string escaped every byte already, so the two agree there.
assert_equal('"る"', "る".inspect)
assert_equal('"\xe3\x82\x8b"', "る".b.inspect)
assert_equal('"\xE3\x82\x8B"', "る".b.inspect)
assert_equal("る".b.dump, "る".b.inspect)
end if UTF8STRING

Expand Down
10 changes: 8 additions & 2 deletions src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,12 @@ str_replace_partial(mrb_state *mrb, mrb_value src, mrb_int pos, mrb_int end, mrb

#define IS_EVSTR(p,e) ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{'))

/* A `\xNN` escape spells its byte in upper case, as CRuby writes it.
`mrb_digitmap` is lower case because `Integer#to_s` reads a number
through it and CRuby spells that in lower case, so the two cannot share
one table. */
static const char escape_hexmap[] = "0123456789ABCDEF";

static mrb_value
str_escape(mrb_state *mrb, mrb_value str, mrb_bool inspect)
{
Expand Down Expand Up @@ -1901,8 +1907,8 @@ str_escape(mrb_state *mrb, mrb_value str, mrb_bool inspect)
}
else {
buf[1] = 'x';
buf[3] = mrb_digitmap[c % 16]; c /= 16;
buf[2] = mrb_digitmap[c % 16];
buf[3] = escape_hexmap[c % 16]; c /= 16;
buf[2] = escape_hexmap[c % 16];
mrb_str_cat(mrb, result, buf, 4);
}
}
Expand Down
4 changes: 3 additions & 1 deletion test/t/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,12 @@ def [](*args)
assert('String#inspect', '15.2.10.5.46') do
assert_equal "\"\\x00\"", "\0".inspect
assert_equal "\"foo\"", "foo".inspect
# a byte spelled out as hex reads out in upper case, the way CRuby writes it
assert_equal "\"\\xAB\"", "\xAB".inspect
if UTF8STRING
assert_equal '"る"', "る".inspect
else
assert_equal '"\xe3\x82\x8b"', "る".inspect
assert_equal '"\xE3\x82\x8B"', "る".inspect
end

# should not raise an exception - regress #1210
Expand Down
2 changes: 1 addition & 1 deletion test/t/vformat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class << v
assert_equal 'percent: %', vf.z('percent: %%')
assert_equal '"I": inspect char', vf.c('%!c: inspect char', ?I)
assert_equal '709: inspect mrb_int', vf.i('%!i: inspect mrb_int', 709)
assert_equal '"a\x00b\xff"', vf.l('%!l', "a\000b\xFFc\000d", 4)
assert_equal '"a\x00b\xFF"', vf.l('%!l', "a\000b\xFFc\000d", 4)
assert_equal ':"&.": inspect symbol', vf.n('%!n: inspect symbol', :'&.')
assert_equal 'inspect "String"', vf.v('inspect %!v', 'String')
assert_equal 'inspect Array: [1, :x, {}]', vf.v('inspect Array: %!v', [1,:x,{}])
Expand Down
Loading