diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-01-29 08:53:45 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-01-29 10:26:18 +0900 |
commit | f6387ae0737ea19a00caa3af14c489b404c1c0e1 (patch) | |
tree | e9fcb1efb5082f8d2d503a06ecd2701175f5d317 /lib/irb/ext | |
parent | c10be4e9db7bec6e9221877c206de6f1589caba4 (diff) |
Fix absolute path predicate on Windows
A path starts with '/' is not an absolute path on Windows, because
of drive letter or UNC.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4127
Diffstat (limited to 'lib/irb/ext')
-rw-r--r-- | lib/irb/ext/loader.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/irb/ext/loader.rb b/lib/irb/ext/loader.rb index 5a198bbef5..90dcd70bd0 100644 --- a/lib/irb/ext/loader.rb +++ b/lib/irb/ext/loader.rb @@ -31,8 +31,31 @@ module IRB # :nodoc: 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 |