file.c: ASCII-compatible

* file.c (rb_file_join): check nul-byte only for strings, since
  FilePathStringValue() does it.  [ruby-core:48012] [Bug #7168]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-10-16 02:27:07 +00:00
parent 7b4f0c0d1d
commit a583f42062
3 changed files with 18 additions and 3 deletions

View File

@ -1,4 +1,7 @@
Tue Oct 16 10:54:03 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Oct 16 11:27:04 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_file_join): check nul-byte only for strings, since
FilePathStringValue() does it. [ruby-core:48012] [Bug #7168]
* file.c (rb_file_join): path names must be ASCII-compatible. * file.c (rb_file_join): path names must be ASCII-compatible.
[ruby-core:48012] [Bug #7168] [ruby-core:48012] [Bug #7168]

4
file.c
View File

@ -3941,6 +3941,7 @@ rb_file_join(VALUE ary, VALUE sep)
tmp = RARRAY_PTR(ary)[i]; tmp = RARRAY_PTR(ary)[i];
switch (TYPE(tmp)) { switch (TYPE(tmp)) {
case T_STRING: case T_STRING:
StringValueCStr(tmp);
break; break;
case T_ARRAY: case T_ARRAY:
if (ary == tmp) { if (ary == tmp) {
@ -3957,8 +3958,7 @@ rb_file_join(VALUE ary, VALUE sep)
default: default:
FilePathStringValue(tmp); FilePathStringValue(tmp);
} }
name = StringValueCStr(result); RSTRING_GETMEM(result, name, len);
len = RSTRING_LEN(result);
if (i == 0) { if (i == 0) {
rb_enc_copy(result, tmp); rb_enc_copy(result, tmp);
} }

View File

@ -793,6 +793,18 @@ class TestFileExhaustive < Test::Unit::TestCase
bug7168 = '[ruby-core:48012]' bug7168 = '[ruby-core:48012]'
names = %w"a b".map {|s| s.encode(Encoding::UTF_16LE)} names = %w"a b".map {|s| s.encode(Encoding::UTF_16LE)}
assert_raise(Encoding::CompatibilityError, bug7168) {File.join(*names)} assert_raise(Encoding::CompatibilityError, bug7168) {File.join(*names)}
assert_raise(Encoding::CompatibilityError, bug7168) {File.join(names)}
a = Object.new
b = names[1]
names = [a, "b"]
a.singleton_class.class_eval do
define_method(:to_path) do
names[1] = b
"a"
end
end
assert_raise(Encoding::CompatibilityError, bug7168) {File.join(names)}
end end
def test_truncate def test_truncate