aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-26 04:04:23 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-26 04:04:23 +0000
commit8948280c67072f652eebc31bc3a2f3fb86bcca5f (patch)
tree8e433b03c6bc0f19f1a166b53d8aea0430e24c97
parent2c181b6d1a0514204e049e5f37529b8b8ccfe434 (diff)
downloadruby-8948280c67072f652eebc31bc3a2f3fb86bcca5f.tar.gz
load.c: search in OS path encoding
* load.c (rb_load_internal): use rb_load_file_str() to keep path encoding. * load.c (rb_require_safe): search in OS path encoding for Windows. * ruby.c (rb_load_file_str): load file with keeping path encoding. * win32/file.c (rb_file_load_ok): use WCHAR type API assuming incoming path is encoded in UTF-8. [ruby-core:56136] [Bug #8676] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--include/ruby/intern.h1
-rw-r--r--load.c5
-rw-r--r--ruby.c8
-rw-r--r--test/ruby/test_require.rb9
-rw-r--r--win32/file.c17
6 files changed, 42 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index e5285235c5..8f8862805c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,14 @@
-Fri Jul 26 13:01:57 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Jul 26 13:04:15 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * load.c (rb_load_internal): use rb_load_file_str() to keep path
+ encoding.
+
+ * load.c (rb_require_safe): search in OS path encoding for Windows.
+
+ * ruby.c (rb_load_file_str): load file with keeping path encoding.
+
+ * win32/file.c (rb_file_load_ok): use WCHAR type API assuming incoming
+ path is encoded in UTF-8. [ruby-core:56136] [Bug #8676]
* file.c (rb_str_encode_ospath): simplify using rb_str_conv_enc().
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index 21adcca752..f30a94d6b5 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -644,6 +644,7 @@ int rb_reg_options(VALUE);
RUBY_EXTERN VALUE rb_argv0;
VALUE rb_get_argv(void);
void *rb_load_file(const char*);
+void *rb_load_file_str(VALUE);
/* signal.c */
VALUE rb_f_kill(int, VALUE*);
#ifdef POSIX_SIGNAL
diff --git a/load.c b/load.c
index 9d95c95fff..03ce062f14 100644
--- a/load.c
+++ b/load.c
@@ -591,7 +591,7 @@ rb_load_internal(VALUE fname, int wrap)
VALUE iseq;
th->mild_compile_error++;
- node = (NODE *)rb_load_file(RSTRING_PTR(fname));
+ node = (NODE *)rb_load_file_str(fname);
loaded = TRUE;
iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), Qfalse);
th->mild_compile_error--;
@@ -941,7 +941,8 @@ rb_require_safe(VALUE fname, int safe)
rb_sourceline());
}
- found = search_required(fname, &path, safe);
+ path = rb_str_encode_ospath(fname);
+ found = search_required(path, &path, safe);
if (RUBY_DTRACE_FIND_REQUIRE_RETURN_ENABLED()) {
RUBY_DTRACE_FIND_REQUIRE_RETURN(StringValuePtr(fname),
diff --git a/ruby.c b/ruby.c
index 2b2e548de8..df3f089267 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1768,8 +1768,14 @@ load_file(VALUE parser, VALUE fname, int script, struct cmdline_options *opt)
void *
rb_load_file(const char *fname)
{
- struct cmdline_options opt;
VALUE fname_v = rb_str_new_cstr(fname);
+ return rb_load_file_str(fname_v);
+}
+
+void *
+rb_load_file_str(VALUE fname_v)
+{
+ struct cmdline_options opt;
return load_file(rb_parser_new(), fname_v, 0, cmdline_options_init(&opt));
}
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
index 8d40f3dd80..41cbff5c02 100644
--- a/test/ruby/test_require.rb
+++ b/test/ruby/test_require.rb
@@ -61,10 +61,17 @@ class TestRequire < Test::Unit::TestCase
def test_require_nonascii_path
bug8165 = '[ruby-core:53733] [Bug #8165]'
- encoding = /mswin|mingw/ =~ RUBY_PLATFORM ? 'filesystem' : 'UTF-8'
+ encoding = 'filesystem'
assert_require_nonascii_path(encoding, bug8165)
end
+ def test_require_nonascii_path_utf8
+ bug8676 = '[ruby-core:56136] [Bug #8676]'
+ encoding = Encoding::UTF_8
+ return if Encoding.find('filesystem') == encoding
+ assert_require_nonascii_path(encoding, bug8676)
+ end
+
def assert_require_nonascii_path(encoding, bug)
Dir.mktmpdir {|tmp|
dir = "\u3042" * 5
diff --git a/win32/file.c b/win32/file.c
index f7b419530f..d43db14c50 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -681,16 +681,22 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
int
rb_file_load_ok(const char *path)
{
+ DWORD attr;
int ret = 1;
- DWORD attr = GetFileAttributes(path);
+ size_t len;
+ wchar_t* wpath;
+
+ convert_mb_to_wchar(path, &wpath, &len, CP_UTF8);
+
+ attr = GetFileAttributesW(wpath);
if (attr == INVALID_FILE_ATTRIBUTES ||
- attr & FILE_ATTRIBUTE_DIRECTORY) {
+ (attr & FILE_ATTRIBUTE_DIRECTORY)) {
ret = 0;
}
else {
- HANDLE h = CreateFile(path, GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ HANDLE h = CreateFileW(wpath, GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h != INVALID_HANDLE_VALUE) {
CloseHandle(h);
}
@@ -698,6 +704,7 @@ rb_file_load_ok(const char *path)
ret = 0;
}
}
+ xfree(wpath);
return ret;
}