Skip to content

Commit

Permalink
Do .irb_history conversion to UTF-8 also on ruby>=3.3
Browse files Browse the repository at this point in the history
This still makes sense when upgrading from RubyInstaller-2.6.5 or older to 3.3.
  • Loading branch information
larskanis committed Dec 25, 2023
1 parent ee56793 commit d808ebc
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions resources/files/irbrc_predefiner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
if irbrc_file && !File.exist?(irbrc_file) && File.exist?(File.dirname(irbrc_file))
File.write irbrc_file, irbrc_text
end

# Try to convert .irb_history from locale to UTF-8, if it isn't encoded properly.
# This is for transition from CP* encodings of RbReadline to UTF-8 of Reline.
history_file = IRB.rc_file("_history")
if File.exist?(history_file) && !(hist=File.read(history_file, encoding: 'utf-8')).valid_encoding?
hist = hist.encode('utf-8', Encoding.find("locale"))
if hist.valid_encoding?
File.write(history_file, hist)
end
end
else
# Remove the now unnecessary .irbrc file when unchanged on newer rubies
if irbrc_file && File.exist?(irbrc_file) && File.read(irbrc_file) == irbrc_text
File.unlink irbrc_file
end
end

# Try to convert .irb_history from locale to UTF-8, if it isn't encoded properly.
# This is for transition from CP* encodings of RbReadline to UTF-8 of Reline.
history_file = IRB.rc_file("_history")
if File.exist?(history_file) && !(hist=File.read(history_file, encoding: 'utf-8')).valid_encoding?
hist = hist.encode('utf-8', Encoding.find("locale"))
if hist.valid_encoding?
File.write(history_file, hist)
end
end

0 comments on commit d808ebc

Please sign in to comment.