From 12b6cd61c0740af71f12c4e1a247ee502e8e78dd Mon Sep 17 00:00:00 2001 From: nagachika Date: Mon, 15 Aug 2016 19:37:18 +0000 Subject: merge revision(s) 55385,55390: [Backport #12483] * file.c (append_fspath): normalize directory name to be appended on OS X. [ruby-core:75957] [Ruby trunk Bug#12483] https://github.com/rails/rails/issues/25303#issuecomment-224834804 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@55909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index 8e9a433b7b..c57447a233 100644 --- a/file.c +++ b/file.c @@ -235,6 +235,7 @@ rb_str_encode_ospath(VALUE path) } #ifdef __APPLE__ +# define NORMALIZE_UTF8PATH 1 static VALUE rb_str_append_normalized_ospath(VALUE str, const char *ptr, long len) { @@ -334,6 +335,8 @@ ignored_char_p(const char *p, const char *e, rb_encoding *enc) } return 0; } +#else +# define NORMALIZE_UTF8PATH 0 #endif static long @@ -3218,6 +3221,18 @@ rb_default_home_dir(VALUE result) } #ifndef _WIN32 +static VALUE +ospath_new(const char *ptr, long len, rb_encoding *fsenc) +{ +#if NORMALIZE_UTF8PATH + VALUE path = rb_str_normalize_ospath(ptr, len); + rb_enc_associate(path, fsenc); + return path; +#else + return rb_enc_str_new(ptr, len, fsenc); +#endif +} + static char * append_fspath(VALUE result, VALUE fname, char *dir, rb_encoding **enc, rb_encoding *fsenc) { @@ -3225,12 +3240,15 @@ append_fspath(VALUE result, VALUE fname, char *dir, rb_encoding **enc, rb_encodi VALUE dirname = Qnil; size_t dirlen = strlen(dir), buflen = rb_str_capacity(result); - if (*enc != fsenc) { - rb_encoding *direnc = rb_enc_check(fname, dirname = rb_enc_str_new(dir, dirlen, fsenc)); + if (NORMALIZE_UTF8PATH || *enc != fsenc) { + rb_encoding *direnc = rb_enc_check(fname, dirname = ospath_new(dir, dirlen, fsenc)); if (direnc != fsenc) { dirname = rb_str_conv_enc(dirname, fsenc, direnc); RSTRING_GETMEM(dirname, cwdp, dirlen); } + else if (NORMALIZE_UTF8PATH) { + RSTRING_GETMEM(dirname, cwdp, dirlen); + } *enc = direnc; } do {buflen *= 2;} while (dirlen > buflen); -- cgit v1.2.3