Last active
December 17, 2015 23:19
-
-
Save terotil/5688138 to your computer and use it in GitHub Desktop.
Needed to work around Ruby File.join returning ASCII-8BIT result. Dunno if aligning argument encodings was strictly necessary for my usecase, but I left it in, even though I noticed that UTF-16 and -32 won't work in any case (ArgumentError: string contains null byte). This workaround blows in your face if there is an argument that can't be encod…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Work around https://bugs.ruby-lang.org/issues/6104 | |
if RUBY_VERSION =~ /^1\.9/ && RUBY_REVISION < 34865 | |
class File | |
class << self | |
def join_with_encoding_fix(*args) | |
target_encoding = args.first.to_s.encoding | |
aligned_args = args.map { |arg| arg.to_s.dup.encode!(target_encoding) } | |
join_without_encoding_fix(*aligned_args).force_encoding(target_encoding) | |
end | |
alias_method :join_without_encoding_fix, :join | |
alias_method :join, :join_with_encoding_fix | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment