aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2014-06-08 20:00:52 -0500
committerJack Nagel2014-06-08 20:00:52 -0500
commit6c9edd47ae8259c82dc5dbeadaa01525ed7edc9b (patch)
treef4af27a7dedd7739f4703be1d1ac8d34ee2626a8 /Library
parent81ba7d0302fbe7fe996f240c4e480b2f2a226004 (diff)
downloadhomebrew-6c9edd47ae8259c82dc5dbeadaa01525ed7edc9b.tar.bz2
Work around encoding issue in Pathname#inspect on Ruby 2.0
Pathname#inspect on Ruby 2.0 throws away the encoding of the object's underlying string and returns a string tagged as ASCII-8BIT. If you simply write puts Pathname.new("some string with non-ascii bytes").inspect no error will be raised, because the implementation of Pathname#inspect does not call into Object#inspect. However, if you wrap that pathname object in an array first, then puts [Pathname.new("some string with non-ascii bytes")].inspect will raise Encoding::CompatibilityError: "inspected result must be ASCII only or use the same encoding with default external". Raising an error in this codepath is new in Ruby 2.0, and this specific bug is fixed in Ruby 2.1. I've opened a bug upstream: https://bugs.ruby-lang.org/issues/9915 Fixes #29947.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/extend/pathname.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb
index 2a2790c12..01746f770 100644
--- a/Library/Homebrew/extend/pathname.rb
+++ b/Library/Homebrew/extend/pathname.rb
@@ -424,6 +424,13 @@ class Pathname
end
end
private :prepend_prefix
+ elsif RUBY_VERSION == "2.0.0"
+ # https://bugs.ruby-lang.org/issues/9915
+ prepend Module.new {
+ def inspect
+ super.force_encoding(instance_variable_get(:@path).encoding)
+ end
+ }
end
end