diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-12 00:24:36 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-12 00:24:36 +0000 |
commit | 797f2eda58dd68965d6ddcaab450f535513e3797 (patch) | |
tree | 45d47251740795c6803db4894f01f6798059b614 /file.c | |
parent | f627ed45146f53875f2fbb88379f2a4ba81f81b8 (diff) |
file.c: normalize cwd
* 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/trunk@55385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -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 #define apply2args(n) (rb_check_arity(argc, n, UNLIMITED_ARGUMENTS), argc-=n) @@ -3211,6 +3214,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) { @@ -3218,12 +3233,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); |