summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshirosaki <shirosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-05 15:30:52 +0000
committershirosaki <shirosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-05 15:30:52 +0000
commit07636ed42ebc9b690846813b492d75bcf32bb62c (patch)
tree941f1b3341ff8fb5ff227f7d5fd1309b4986688b
parent21d47b7381ae6da9e6ffe1aa288b295af8e3b3d1 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--load.c6
-rw-r--r--test/ruby/test_require.rb21
3 files changed, 33 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 8292863633..6a59b5069e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Apr 6 00:19:30 2013 Hiroshi Shirosaki <h.shirosaki@gmail.com>
+
+ * 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@fsij.org>
* include/ruby/defines.h (HAVE_TRUE_LONG_LONG): Defined to distinguish
diff --git a/load.c b/load.c
index 7c69461a8e..dab493da70 100644
--- a/load.c
+++ b/load.c
@@ -247,16 +247,16 @@ features_index_add(VALUE feature, VALUE offset)
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);
}
}
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
index bca6a9754c..2e7b37d138 100644
--- a/test/ruby/test_require.rb
+++ b/test/ruby/test_require.rb
@@ -59,6 +59,27 @@ class TestRequire < Test::Unit::TestCase
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