file.c: ASCII-compatible
* file.c (rb_file_join): path names must be ASCII-compatible. [ruby-core:48012] [Bug #7168] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ad54de2aca
commit
7b4f0c0d1d
@ -1,4 +1,7 @@
|
|||||||
Tue Oct 16 10:53:29 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Oct 16 10:54:03 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* file.c (rb_file_join): path names must be ASCII-compatible.
|
||||||
|
[ruby-core:48012] [Bug #7168]
|
||||||
|
|
||||||
* file.c (check_path_encoding): new function to ensure path name
|
* file.c (check_path_encoding): new function to ensure path name
|
||||||
encoding to be ASCII-compatible.
|
encoding to be ASCII-compatible.
|
||||||
|
1
file.c
1
file.c
@ -3924,6 +3924,7 @@ rb_file_join(VALUE ary, VALUE sep)
|
|||||||
for (i=0; i<RARRAY_LEN(ary); i++) {
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
||||||
tmp = RARRAY_PTR(ary)[i];
|
tmp = RARRAY_PTR(ary)[i];
|
||||||
if (RB_TYPE_P(tmp, T_STRING)) {
|
if (RB_TYPE_P(tmp, T_STRING)) {
|
||||||
|
check_path_encoding(tmp);
|
||||||
len += RSTRING_LEN(tmp);
|
len += RSTRING_LEN(tmp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -772,10 +772,14 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||||||
s = "foo" + File::SEPARATOR + "bar" + File::SEPARATOR + "baz"
|
s = "foo" + File::SEPARATOR + "bar" + File::SEPARATOR + "baz"
|
||||||
assert_equal(s, File.join("foo", "bar", "baz"))
|
assert_equal(s, File.join("foo", "bar", "baz"))
|
||||||
assert_equal(s, File.join(["foo", "bar", "baz"]))
|
assert_equal(s, File.join(["foo", "bar", "baz"]))
|
||||||
|
|
||||||
o = Object.new
|
o = Object.new
|
||||||
def o.to_path; "foo"; end
|
def o.to_path; "foo"; end
|
||||||
assert_equal(s, File.join(o, "bar", "baz"))
|
assert_equal(s, File.join(o, "bar", "baz"))
|
||||||
assert_equal(s, File.join("foo" + File::SEPARATOR, "bar", File::SEPARATOR + "baz"))
|
assert_equal(s, File.join("foo" + File::SEPARATOR, "bar", File::SEPARATOR + "baz"))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_join_alt_separator
|
||||||
if File::ALT_SEPARATOR == '\\'
|
if File::ALT_SEPARATOR == '\\'
|
||||||
a = "\225\\"
|
a = "\225\\"
|
||||||
b = "foo"
|
b = "foo"
|
||||||
@ -785,6 +789,12 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_join_ascii_incompatible
|
||||||
|
bug7168 = '[ruby-core:48012]'
|
||||||
|
names = %w"a b".map {|s| s.encode(Encoding::UTF_16LE)}
|
||||||
|
assert_raise(Encoding::CompatibilityError, bug7168) {File.join(*names)}
|
||||||
|
end
|
||||||
|
|
||||||
def test_truncate
|
def test_truncate
|
||||||
assert_equal(0, File.truncate(@file, 1))
|
assert_equal(0, File.truncate(@file, 1))
|
||||||
file_assertion.exist?(@file)
|
file_assertion.exist?(@file)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user