Skip to content

Commit b510bc6

Browse files
committed
Fix puts for strings with non-ASCII-compatible encodings.
1 parent 7adcacb commit b510bc6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ New features:
5555
* Fixed error when using arrows keys first within `irb` or `pry` (#1478, #1486).
5656
* Fixed `String#inspect` when the string uses a non-UTF-8 ASCII-compatible
5757
encoding and has non-ASCII characters.
58+
* Fixed `puts` for strings with non-ASCII-compatible encodings.
5859

5960
Changes:
6061

src/main/ruby/core/truffle/io_operations.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,16 @@ def self.puts(io, *args)
5252
end
5353

5454
if str
55-
# Truffle: write the string + record separator (\n) atomically so multithreaded #puts is bearable
56-
unless str.end_with?(DEFAULT_RECORD_SEPARATOR)
57-
str += DEFAULT_RECORD_SEPARATOR
55+
# Truffle: write the string + record separator (\n) atomically so multi-threaded #puts is bearable
56+
if str.encoding.ascii_compatible?
57+
unless str.end_with?(DEFAULT_RECORD_SEPARATOR)
58+
str += DEFAULT_RECORD_SEPARATOR
59+
end
60+
else
61+
rs = DEFAULT_RECORD_SEPARATOR.encode(str.encoding)
62+
unless str.end_with?(rs)
63+
str += rs
64+
end
5865
end
5966
io.write str
6067
end

0 commit comments

Comments
 (0)