ruby-changes:65077
From: Nobuyoshi <ko1@a...>
Date: Fri, 29 Jan 2021 10:26:44 +0900 (JST)
Subject: [ruby-changes:65077] f6387ae073 (master): Fix absolute path predicate on Windows
https://git.ruby-lang.org/ruby.git/commit/?id=f6387ae073 From f6387ae0737ea19a00caa3af14c489b404c1c0e1 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 29 Jan 2021 08:53:45 +0900 Subject: Fix absolute path predicate on Windows A path starts with '/' is not an absolute path on Windows, because of drive letter or UNC. --- lib/irb/ext/loader.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/irb/ext/loader.rb b/lib/irb/ext/loader.rb index 5a198bb..90dcd70 100644 --- a/lib/irb/ext/loader.rb +++ b/lib/irb/ext/loader.rb @@ -31,8 +31,31 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/ext/loader.rb#L31 load_file(path, priv) end + if File.respond_to?(:absolute_path?) + def absolute_path?(path) + File.absolute_path?(path) + end + else + separator = + if File::ALT_SEPARATOR + File::SEPARATOR + else + "[#{Regexp.quote(File::SEPARATOR + File::ALT_SEPARATOR)}]" + end + ABSOLUTE_PATH_PATTERN = # :nodoc: + case Dir.pwd + when /\A\w:/, /\A#{separator}{2}/ + /\A(?:\w:|#{separator})#{separator}/ + else + /\A#{separator}/ + end + def absolute_path?(path) + ABSOLUTE_PATH_PATTERN =~ path + end + end + def search_file_from_ruby_path(fn) # :nodoc: - if /^#{Regexp.quote(File::Separator)}/ =~ fn + if absolute_path?(fn) return fn if File.exist?(fn) return nil end -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/