Skip to content

Commit

Permalink
Merge pull request #72 from kylog/dont-break-file-scheme-with-unc-on-…
Browse files Browse the repository at this point in the history
…windows

Dont break file scheme with unc on windows
  • Loading branch information
hoxworth committed Dec 31, 2013
2 parents 136a01e + 104d2ac commit 6fbba9e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/json-schema/uri/file.rb
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

0 comments on commit 6fbba9e

Please sign in to comment.