From 6e37bdc69f2d910432d20d5e29b8c8268aa06eb4 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Tue, 8 Jun 2010 06:30:35 +0000 Subject: [PATCH] merge revision(s) 27398: * eval.c (search_required): expand home relative path first. [ruby-core:29610] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@28210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ eval.c | 6 +++++- test/ruby/test_require.rb | 27 +++++++++++++++++++++++++++ version.h | 2 +- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 test/ruby/test_require.rb diff --git a/ChangeLog b/ChangeLog index efe43f5266..b800fcd68d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Jun 8 15:27:00 2010 Nobuyoshi Nakada + + * eval.c (search_required): expand home relative path first. + [ruby-core:29610] + Tue Jun 8 15:23:10 2010 Nobuyoshi Nakada * lib/timeout.rb (Timeout#timeout): propagate errors to the diff --git a/eval.c b/eval.c index 94a702072c..8abfbb8af6 100644 --- a/eval.c +++ b/eval.c @@ -7328,9 +7328,13 @@ search_required(fname, featurep, path) const char *ext, *ftptr; int type; + if (*(ftptr = RSTRING_PTR(fname)) == '~') { + fname = rb_file_expand_path(fname, Qnil); + ftptr = RSTRING_PTR(fname); + } *featurep = fname; *path = 0; - ext = strrchr(ftptr = RSTRING_PTR(fname), '.'); + ext = strrchr(ftptr, '.'); if (ext && !strchr(ext, '/')) { if (strcmp(".rb", ext) == 0) { if (rb_feature_p(ftptr, ext, Qtrue)) { diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb new file mode 100644 index 0000000000..aa96d4eabe --- /dev/null +++ b/test/ruby/test_require.rb @@ -0,0 +1,27 @@ +require 'test/unit' + +require 'tempfile' +require File.expand_path('../envutil', __FILE__) +require 'tmpdir' + +class TestRequire < Test::Unit::TestCase + def test_home_path + home = ENV["HOME"] + bug3171 = '[ruby-core:29610]' + Dir.mktmpdir do |tmp| + ENV["HOME"] = tmp + name = "loadtest#{$$}-1" + path = File.join(tmp, name) << ".rb" + open(path, "w") {} + require "~/#{name}" + assert_equal(path, $"[-1], bug3171) + name.succ! + path = File.join(tmp, name << ".rb") + open(path, "w") {} + require "~/#{name}" + assert_equal(path, $"[-1], bug3171) + end + ensure + ENV["HOME"] = home + end +end diff --git a/version.h b/version.h index e56c88fe29..6a0f5a0c9f 100644 --- a/version.h +++ b/version.h @@ -2,7 +2,7 @@ #define RUBY_RELEASE_DATE "2010-06-08" #define RUBY_VERSION_CODE 187 #define RUBY_RELEASE_CODE 20100608 -#define RUBY_PATCHLEVEL 274 +#define RUBY_PATCHLEVEL 275 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 8