mirror of
https://github.com/ruby/ruby.git
synced 2025-09-19 02:23:59 +02:00
* file.c (append_fspath): filesystem encoding is prior to the encoding
of argument. * file.c (rb_file_expand_path_internal, EXPAND_PATH_BUFFER): ignore the encoding of the given path name, use filesystem encoding always instead. [ruby-dev:39393] [Bug #2154] * test/ruby/test_file_exhaustive.rb: removed 2.0 spec tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@37562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d8665830b7
commit
88566f08b7
5 changed files with 18 additions and 47 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Thu Nov 8 17:37:54 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* file.c (append_fspath): filesystem encoding is prior to the encoding
|
||||||
|
of argument.
|
||||||
|
|
||||||
|
* file.c (rb_file_expand_path_internal, EXPAND_PATH_BUFFER): ignore
|
||||||
|
the encoding of the given path name, use filesystem encoding always
|
||||||
|
instead. [ruby-dev:39393] [Bug #2154]
|
||||||
|
|
||||||
|
* test/ruby/test_file_exhaustive.rb: removed 2.0 spec tests.
|
||||||
|
|
||||||
Thu Nov 8 17:33:53 2012 Luis Lavena <luislavena@gmail.com>
|
Thu Nov 8 17:33:53 2012 Luis Lavena <luislavena@gmail.com>
|
||||||
|
|
||||||
* ext/zlib/extconf.rb: Recognize zlibwapi as linking library.
|
* ext/zlib/extconf.rb: Recognize zlibwapi as linking library.
|
||||||
|
|
9
file.c
9
file.c
|
@ -2875,7 +2875,7 @@ append_fspath(VALUE result, VALUE fname, char *dir, rb_encoding **enc, rb_encodi
|
||||||
size_t dirlen = strlen(dir), buflen = rb_str_capacity(result);
|
size_t dirlen = strlen(dir), buflen = rb_str_capacity(result);
|
||||||
|
|
||||||
if (*enc != fsenc) {
|
if (*enc != fsenc) {
|
||||||
rb_encoding *direnc = rb_enc_check(fname, dirname = rb_enc_str_new(dir, dirlen, fsenc));
|
rb_encoding *direnc = rb_enc_check(dirname = rb_enc_str_new(dir, dirlen, fsenc), fname);
|
||||||
if (direnc != fsenc) {
|
if (direnc != fsenc) {
|
||||||
dirname = rb_str_conv_enc(dirname, fsenc, direnc);
|
dirname = rb_str_conv_enc(dirname, fsenc, direnc);
|
||||||
RSTRING_GETMEM(dirname, cwdp, dirlen);
|
RSTRING_GETMEM(dirname, cwdp, dirlen);
|
||||||
|
@ -2980,7 +2980,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
|
||||||
else if (!rb_is_absolute_path(s)) {
|
else if (!rb_is_absolute_path(s)) {
|
||||||
if (!NIL_P(dname)) {
|
if (!NIL_P(dname)) {
|
||||||
rb_file_expand_path_internal(dname, Qnil, abs_mode, long_name, result);
|
rb_file_expand_path_internal(dname, Qnil, abs_mode, long_name, result);
|
||||||
rb_enc_associate(result, rb_enc_check(result, fname));
|
rb_enc_check(result, fname);
|
||||||
BUFINIT();
|
BUFINIT();
|
||||||
p = pend;
|
p = pend;
|
||||||
}
|
}
|
||||||
|
@ -3009,7 +3009,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
|
||||||
BUFCHECK(bdiff >= buflen);
|
BUFCHECK(bdiff >= buflen);
|
||||||
memset(buf, '/', len);
|
memset(buf, '/', len);
|
||||||
rb_str_set_len(result, len);
|
rb_str_set_len(result, len);
|
||||||
rb_enc_associate(result, rb_enc_check(result, fname));
|
rb_enc_check(result, fname);
|
||||||
}
|
}
|
||||||
if (p > buf && p[-1] == '/')
|
if (p > buf && p[-1] == '/')
|
||||||
--p;
|
--p;
|
||||||
|
@ -3228,13 +3228,12 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
|
||||||
|
|
||||||
if (tainted) OBJ_TAINT(result);
|
if (tainted) OBJ_TAINT(result);
|
||||||
rb_str_set_len(result, p - buf);
|
rb_str_set_len(result, p - buf);
|
||||||
rb_enc_check(fname, result);
|
|
||||||
ENC_CODERANGE_CLEAR(result);
|
ENC_CODERANGE_CLEAR(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#define EXPAND_PATH_BUFFER() rb_usascii_str_new(0, MAXPATHLEN + 2)
|
#define EXPAND_PATH_BUFFER() rb_enc_str_new(0, MAXPATHLEN + 2, rb_filesystem_encoding())
|
||||||
|
|
||||||
#define check_expand_path_args(fname, dname) \
|
#define check_expand_path_args(fname, dname) \
|
||||||
(((fname) = rb_get_path(fname)), \
|
(((fname) = rb_get_path(fname)), \
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- coding: us-ascii -*-
|
||||||
require "test/unit"
|
require "test/unit"
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
require "tmpdir"
|
require "tmpdir"
|
||||||
|
@ -412,46 +413,6 @@ class TestFileExhaustive < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_expand_path_encoding
|
|
||||||
drive = (DRIVE ? 'C:' : '')
|
|
||||||
if Encoding.find("filesystem") == Encoding::CP1251
|
|
||||||
a = "#{drive}/\u3042\u3044\u3046\u3048\u304a".encode("cp932")
|
|
||||||
else
|
|
||||||
a = "#{drive}/\u043f\u0440\u0438\u0432\u0435\u0442".encode("cp1251")
|
|
||||||
end
|
|
||||||
assert_equal(a, File.expand_path(a))
|
|
||||||
a = "#{drive}/\225\\\\"
|
|
||||||
if File::ALT_SEPARATOR == '\\'
|
|
||||||
[%W"cp437 #{drive}/\225", %W"cp932 #{drive}/\225\\"]
|
|
||||||
else
|
|
||||||
[["cp437", a], ["cp932", a]]
|
|
||||||
end.each do |cp, expected|
|
|
||||||
assert_equal(expected.force_encoding(cp), File.expand_path(a.dup.force_encoding(cp)), cp)
|
|
||||||
end
|
|
||||||
|
|
||||||
path = "\u3042\u3044\u3046\u3048\u304a".encode("EUC-JP")
|
|
||||||
assert_equal("#{Dir.pwd}/#{path}".encode("CP932"), File.expand_path(path).encode("CP932"))
|
|
||||||
|
|
||||||
path = "\u3042\u3044\u3046\u3048\u304a".encode("CP51932")
|
|
||||||
assert_equal("#{Dir.pwd}/#{path}", File.expand_path(path))
|
|
||||||
|
|
||||||
assert_incompatible_encoding {|d| File.expand_path(d)}
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_expand_path_encoding_filesystem
|
|
||||||
home = ENV["HOME"]
|
|
||||||
ENV["HOME"] = "#{DRIVE}/UserHome"
|
|
||||||
|
|
||||||
path = "~".encode("US-ASCII")
|
|
||||||
dir = "C:/".encode("IBM437")
|
|
||||||
fs = Encoding.find("filesystem")
|
|
||||||
|
|
||||||
assert_equal fs, File.expand_path(path).encoding
|
|
||||||
assert_equal fs, File.expand_path(path, dir).encoding
|
|
||||||
ensure
|
|
||||||
ENV["HOME"] = home
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_expand_path_home
|
def test_expand_path_home
|
||||||
assert_kind_of(String, File.expand_path("~")) if ENV["HOME"]
|
assert_kind_of(String, File.expand_path("~")) if ENV["HOME"]
|
||||||
assert_raise(ArgumentError) { File.expand_path("~foo_bar_baz_unknown_user_wahaha") }
|
assert_raise(ArgumentError) { File.expand_path("~foo_bar_baz_unknown_user_wahaha") }
|
||||||
|
|
|
@ -350,7 +350,7 @@ class TestRequire < Test::Unit::TestCase
|
||||||
$: << tmp
|
$: << tmp
|
||||||
open(File.join(tmp, "foo.rb"), "w") {}
|
open(File.join(tmp, "foo.rb"), "w") {}
|
||||||
require "foo"
|
require "foo"
|
||||||
assert_equal(tmp.encoding, $"[0].encoding, bug6377)
|
assert_not_equal(Encoding::ASCII_8BIT, $"[0].encoding, bug6377)
|
||||||
}
|
}
|
||||||
ensure
|
ensure
|
||||||
$:.replace(loadpath)
|
$:.replace(loadpath)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#define RUBY_VERSION "1.9.3"
|
#define RUBY_VERSION "1.9.3"
|
||||||
#define RUBY_PATCHLEVEL 317
|
#define RUBY_PATCHLEVEL 318
|
||||||
|
|
||||||
#define RUBY_RELEASE_DATE "2012-11-08"
|
#define RUBY_RELEASE_DATE "2012-11-08"
|
||||||
#define RUBY_RELEASE_YEAR 2012
|
#define RUBY_RELEASE_YEAR 2012
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue