@@ -578,7 +578,7 @@ def inspect
578
578
char = chr_at index
579
579
580
580
if char
581
- index += inspect_char ( ascii , unicode , index , char , array )
581
+ index += inspect_char ( enc , result_encoding , ascii , unicode , index , char , array )
582
582
else
583
583
array << "\\ x#{ getbyte ( index ) . to_s ( 16 ) } "
584
584
index += 1
@@ -595,10 +595,10 @@ def inspect
595
595
end
596
596
597
597
Truffle ::Type . infect result , self
598
- result . force_encoding result_encoding
598
+ result . encode ( result_encoding , encoding )
599
599
end
600
600
601
- def inspect_char ( ascii , unicode , index , char , array )
601
+ def inspect_char ( enc , result_encoding , ascii , unicode , index , char , array )
602
602
consumed = char . bytesize
603
603
604
604
if ( ascii or unicode ) and consumed == 1
@@ -648,7 +648,8 @@ def inspect_char(ascii, unicode, index, char, array)
648
648
end
649
649
end
650
650
651
- if Truffle . invoke_primitive ( :character_printable_p , char )
651
+ if ( enc == result_encoding && Truffle . invoke_primitive ( :character_printable_p , char ) ) ||
652
+ ( ascii && char . ascii_only? && Truffle . invoke_primitive ( :character_printable_p , char ) )
652
653
array << char
653
654
else
654
655
code = char . ord
0 commit comments