diff --git a/dln_find.c b/dln_find.c index 2d2bd1bd296..aeb9390caeb 100644 --- a/dln_find.c +++ b/dln_find.c @@ -124,8 +124,9 @@ dln_find_1(const char *fname, const char *path, char *fbuf, size_t size, return NULL; } #ifdef DOSISH -# ifndef CharNext -# define CharNext(p) ((p)+1) +# ifndef DLN_CHAR_NEXT +/* fname is UTF-8 unless win32.c includes this file with its code page */ +# define DLN_CHAR_NEXT(p) ((p)+1) # endif # ifdef DOSISH_DRIVE_LETTER if ((unsigned char)((p[0] | 0x20) - 'a') < 26u && p[1] == ':') { @@ -151,7 +152,7 @@ dln_find_1(const char *fname, const char *path, char *fbuf, size_t size, p++; break; default: - p = CharNext(p); + p = DLN_CHAR_NEXT(p); } } if (ext) { diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 1fc8f31240b..b0815abc1c4 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -1166,6 +1166,21 @@ class TestProcess < Test::Unit::TestCase } end + def test_exec_relative_path_after_multibyte_dir + return unless windows? + with_tmpchdir {|d| + dir = "\u{3042}" + Dir.mkdir(dir) + File.write("#{dir}/foo.cmd", "@echo cwd\n") + Dir.mkdir("path") + Dir.mkdir("path/#{dir}") + File.write("path/#{dir}/foo.cmd", "@echo path\n") + env = {"PATH"=>"#{d}/path;#{ENV["PATH"]}"} + r = IO.popen([env, RUBY, "-e", "exec(*ARGV)", "#{dir}\\foo", "x"], &:read) + assert_equal("cwd", r.chomp) + } + end + def test_system_wordsplit with_tmpchdir {|d| File.write("script", <<-'End') diff --git a/win32/win32.c b/win32/win32.c index 39186d6da6c..578d2a56a98 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -81,8 +81,7 @@ static char *w32_getenv(const char *name, UINT cp); #define DLN_FIND_EXTRA_ARG ,cp #define rb_w32_stati128(path, st) w32_stati128(path, st, cp, FALSE) #define getenv(name) w32_getenv(name, cp) /* Necessarily For dln.c */ -#undef CharNext -#define CharNext(p) CharNextExA(cp, (p), 0) +#define DLN_CHAR_NEXT(p) CharNextExA(cp, (p), 0) #define dln_find_exe_r rb_w32_udln_find_exe_r #define dln_find_file_r rb_w32_udln_find_file_r #include "dln.h"