ruby-changes:28083
From: shirosaki <ko1@a...>
Date: Sat, 6 Apr 2013 00:31:12 +0900 (JST)
Subject: [ruby-changes:28083] shirosaki:r40135 (trunk): * load.c (features_index_add): use rb_str_subseq() to specify C string
shirosaki 2013-04-06 00:30:52 +0900 (Sat, 06 Apr 2013) New Revision: 40135 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40135 Log: * load.c (features_index_add): use rb_str_subseq() to specify C string position properly to fix require non ascii path. [ruby-core:53733] [Bug #8165] * test/ruby/test_require.rb (TestRequire#test_require_nonascii_path): a test for the above. Modified files: trunk/ChangeLog trunk/load.c trunk/test/ruby/test_require.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 40134) +++ ChangeLog (revision 40135) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Apr 6 00:19:30 2013 Hiroshi Shirosaki <h.shirosaki@g...> + + * load.c (features_index_add): use rb_str_subseq() to specify C string + position properly to fix require non ascii path. + [ruby-core:53733] [Bug #8165] + + * test/ruby/test_require.rb (TestRequire#test_require_nonascii_path): + a test for the above. + Fri Apr 5 20:41:49 2013 Tanaka Akira <akr@f...> * include/ruby/defines.h (HAVE_TRUE_LONG_LONG): Defined to distinguish Index: load.c =================================================================== --- load.c (revision 40134) +++ load.c (revision 40135) @@ -247,16 +247,16 @@ features_index_add(VALUE feature, VALUE https://github.com/ruby/ruby/blob/trunk/load.c#L247 if (p < feature_str) break; /* Now *p == '/'. We reach this point for every '/' in `feature`. */ - short_feature = rb_str_substr(feature, p + 1 - feature_str, feature_end - p - 1); + short_feature = rb_str_subseq(feature, p + 1 - feature_str, feature_end - p - 1); features_index_add_single(short_feature, offset); if (ext) { - short_feature = rb_str_substr(feature, p + 1 - feature_str, ext - p - 1); + short_feature = rb_str_subseq(feature, p + 1 - feature_str, ext - p - 1); features_index_add_single(short_feature, offset); } } features_index_add_single(feature, offset); if (ext) { - short_feature = rb_str_substr(feature, 0, ext - feature_str); + short_feature = rb_str_subseq(feature, 0, ext - feature_str); features_index_add_single(short_feature, offset); } } Index: test/ruby/test_require.rb =================================================================== --- test/ruby/test_require.rb (revision 40134) +++ test/ruby/test_require.rb (revision 40135) @@ -59,6 +59,27 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L59 end end + def test_require_nonascii_path + bug8165 = '[ruby-core:53733] [Bug #8165]' + Dir.mktmpdir {|tmp| + encoding = /mswin|mingw/ =~ RUBY_PLATFORM ? 'filesystem' : 'UTF-8' + dir = "\u3042" * 5 + begin + require_path = File.join(tmp, dir, 'foo.rb').encode(encoding) + rescue + skip "cannot convert path encoding to #{encoding}" + end + Dir.mkdir(File.dirname(require_path)) + open(require_path, "wb") {} + assert_in_out_err([], <<-INPUT, %w(:ok), [], bug8165) + # coding: #{encoding} + $:.replace([IO::NULL] + $:.reject {|path| path !~ /\.ext/}) + p :ok if require '#{require_path}' + p :ng if require '#{require_path}' + INPUT + } + end + def test_require_path_home_1 env_rubypath, env_home = ENV["RUBYPATH"], ENV["HOME"] pathname_too_long = /pathname too long \(ignored\).*\(LoadError\)/m -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/