From: "aparker42 (Andrew Parker)" Date: 2012-10-19T01:33:44+09:00 Subject: [ruby-core:48066] [ruby-trunk - Bug #7168] File.join trips over string encodings Issue #7168 has been updated by aparker42 (Andrew Parker). You are right that Darwin doesn't have this problem, as far as I know. As I pointed out the problem was originally found on Windows, where the filesystem uses UTF-16. Why is the behavior that I expected (that File.join can work with any String) wrong? ---------------------------------------- Bug #7168: File.join trips over string encodings https://bugs.ruby-lang.org/issues/7168#change-31015 Author: aparker42 (Andrew Parker) Status: Closed Priority: Normal Assignee: Category: Target version: ruby -v: ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0] It seems like `File.join` is unable to handle string encodings that contain null bytes even though the string is properly encoded. This causes it to be unable to process inputs when the filenames on the system are encoded in this manner. From an irb session: 1.9.3p125 :013 > File.join("a".encode("UTF-16LE")).encoding => # 1.9.3p125 :014 > File.join("a".encode("UTF-16LE"), "".encode("UTF-16LE")) ArgumentError: string contains null byte from (irb):14:in `join' from (irb):14 from /Users/andy/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `
' I would expect the second command in that session to return "a/" just like `File.join("a", "")` does, but with the UTF-16LE encoding. See for where this came from. -- http://bugs.ruby-lang.org/