mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
dir.c: compose HFS file names
* dir.c (dir_each): compose HFS file names from UTF8-MAC. [ruby-core:48745] [Bug #7267] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a7092270da
commit
1891b60f26
3 changed files with 42 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Tue May 21 03:11:18 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* dir.c (dir_each): compose HFS file names from
|
||||||
|
UTF8-MAC. [ruby-core:48745] [Bug #7267]
|
||||||
|
|
||||||
Tue May 21 03:08:52 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue May 21 03:08:52 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* test/ruby/envutil.rb (assert_separately): require envutil in the
|
* test/ruby/envutil.rb (assert_separately): require envutil in the
|
||||||
|
|
18
dir.c
18
dir.c
|
@ -663,12 +663,28 @@ dir_each(VALUE dir)
|
||||||
struct dir_data *dirp;
|
struct dir_data *dirp;
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT entry);
|
IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT entry);
|
||||||
|
IF_HAVE_HFS(int hfs_p);
|
||||||
|
|
||||||
RETURN_ENUMERATOR(dir, 0, 0);
|
RETURN_ENUMERATOR(dir, 0, 0);
|
||||||
GetDIR(dir, dirp);
|
GetDIR(dir, dirp);
|
||||||
rewinddir(dirp->dir);
|
rewinddir(dirp->dir);
|
||||||
|
IF_HAVE_HFS(hfs_p = !NIL_P(dirp->path) && is_hfs(RSTRING_PTR(dirp->path)));
|
||||||
while (READDIR(dirp->dir, dirp->enc, &STRUCT_DIRENT(entry), dp)) {
|
while (READDIR(dirp->dir, dirp->enc, &STRUCT_DIRENT(entry), dp)) {
|
||||||
rb_yield(rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc));
|
const char *name = dp->d_name;
|
||||||
|
size_t namlen = NAMLEN(dp);
|
||||||
|
VALUE path;
|
||||||
|
#if HAVE_HFS
|
||||||
|
VALUE utf8str = Qnil;
|
||||||
|
rb_encoding *utf8mac = 0;
|
||||||
|
if (hfs_p && has_nonascii(name, namlen) && (utf8mac = rb_utf8mac_encoding()) != 0) {
|
||||||
|
utf8str = rb_str_conv_enc(rb_tainted_str_new(name, namlen),
|
||||||
|
utf8mac, rb_utf8_encoding());
|
||||||
|
RSTRING_GETMEM(utf8str, name, namlen);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
path = rb_external_str_new_with_enc(name, namlen, dirp->enc);
|
||||||
|
IF_HAVE_HFS(if (!NIL_P(utf8str)) rb_str_resize(utf8str, 0));
|
||||||
|
rb_yield(path);
|
||||||
if (dirp->dir == NULL) dir_closed();
|
if (dirp->dir == NULL) dir_closed();
|
||||||
}
|
}
|
||||||
return dir;
|
return dir;
|
||||||
|
|
|
@ -305,4 +305,24 @@ class TestDir_M17N < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_entries_compose
|
||||||
|
bug7267 = '[ruby-core:48745] [Bug #7267]'
|
||||||
|
|
||||||
|
pp = Object.new.extend(Test::Unit::Assertions)
|
||||||
|
def pp.mu_pp(ary) #:nodoc:
|
||||||
|
'[' << ary.map {|str| "#{str.dump}(#{str.encoding})"}.join(', ') << ']'
|
||||||
|
end
|
||||||
|
|
||||||
|
with_tmpdir {|d|
|
||||||
|
orig = %W"d\u{e9}tente x\u{304c 304e 3050 3052 3054}"
|
||||||
|
orig.each {|n| open(n, "w") {}}
|
||||||
|
if /mswin|mingw/ =~ RUBY_PLATFORM
|
||||||
|
opts = {:encoding => Encoding.default_external}
|
||||||
|
orig.map! {|o| o.encode(Encoding.find("filesystem")) rescue o.tr("^a-z", "?")}
|
||||||
|
end
|
||||||
|
ents = Dir.entries(".", opts).reject {|n| /\A\./ =~ n}
|
||||||
|
pp.assert_equal(orig, ents, bug7267)
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue