Skip to content

Commit 7dabaaa

Browse files
committed
[GR-19220] Fix broken UTF-8 inspect (#1842).
PullRequest: truffleruby/1175
2 parents b35896d + 969b945 commit 7dabaaa

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Bug fixes:
3333
* Arrays backed by native storage now allocate the correct amount of memory (#1828).
3434
* Fixed issue in `ConditionVariable#wait` that could lose a `ConditionVariable#signal`.
3535
* Do not leak TruffleRuby specific method Array#swap (#1816)
36+
* Fixed `#inspect` on broken UTF-8 sequences (#1842, @chrisseaton).
3637

3738
Compatibility:
3839

spec/ruby/core/string/inspect_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@
319319
0.chr.inspect.should == '"\\x00"'
320320
end
321321

322+
it "uses \\x notation for broken UTF-8 sequences" do
323+
"\xF0\x9F".inspect.should == '"\\xF0\\x9F"'
324+
end
325+
322326
describe "when default external is UTF-8" do
323327
before :each do
324328
@extenc, Encoding.default_external = Encoding.default_external, Encoding::UTF_8

src/main/ruby/truffleruby/core/string.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ def inspect
571571
if char
572572
index += inspect_char(enc, result_encoding, ascii, unicode, index, char, array)
573573
else
574-
array << "\\x#{getbyte(index).to_s(16)}"
574+
array << "\\x#{getbyte(index).to_s(16).upcase}"
575575
index += 1
576576
end
577577
end

0 commit comments

Comments
 (0)