mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix absolute path predicate on Windows
A path starts with '/' is not an absolute path on Windows, because of drive letter or UNC.
This commit is contained in:
parent
c10be4e9db
commit
f6387ae073
Notes:
git
2021-01-29 10:26:49 +09:00
1 changed files with 24 additions and 1 deletions
|
@ -31,8 +31,31 @@ module IRB # :nodoc:
|
||||||
load_file(path, priv)
|
load_file(path, priv)
|
||||||
end
|
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:
|
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 fn if File.exist?(fn)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue