-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from kylog/dont-break-file-scheme-with-unc-on-…
…windows Dont break file scheme with unc on windows
- Loading branch information
Showing
1 changed file
with
13 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,36 @@ | ||
require 'rbconfig' | ||
require 'uri' | ||
|
||
module URI | ||
|
||
# Ruby does not have built-in support for filesystem URIs, and definitely does not have built-in support for | ||
# using open-uri with filesystem URIs | ||
class File < Generic | ||
|
||
COMPONENT = [ | ||
:scheme, | ||
:path, | ||
:scheme, | ||
:path, | ||
:fragment, | ||
:host | ||
].freeze | ||
|
||
def initialize(*arg) | ||
arg[2] = "" | ||
# arg[2] is the 'host'; this logic to set it to "" causes file schemes with UNC to break | ||
# so don't do it on windows platforms | ||
is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) | ||
arg[2] = "" unless is_windows | ||
super(*arg) | ||
end | ||
|
||
def self.build(args) | ||
tmp = Util::make_components_hash(self, args) | ||
return super(tmp) | ||
end | ||
|
||
def open(*rest, &block) | ||
::File.open(self.path, *rest, &block) | ||
end | ||
|
||
@@schemes['FILE'] = File | ||
end | ||
end | ||
end |