Skip to content

Commit 14d6af0

Browse files
committed
Don't expand paths relative to __FILE__ in metadata and reader.
1 parent d0709b4 commit 14d6af0

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

lib/rdf/tabular/metadata.rb

+3-8
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,9 @@ def self.open(path, **options)
142142
'Accept' => 'application/ld+json, application/json'
143143
}
144144
)
145-
if RDF::URI(path).relative?
146-
path = if Gem.win_platform?
147-
# Expanded path starts with drive letter
148-
"file:/" + File.expand_path(path, __FILE__)
149-
else
150-
"file:#{File.expand_path(path, __FILE__)}"
151-
end
152-
end
145+
146+
# Resolve relative paths to use the file scheme, bearing in mind that Windows expanded paths always start with a drive letter, not a slash.
147+
path = (Gem.win_platform? ? "file:/" : "file:") + File.expand_path(path) if RDF::URI(path).relative?
153148
RDF::Util::File.open_file(path, **options) do |file|
154149
self.new(file, **options.merge(base: path, filenames: path))
155150
end

lib/rdf/tabular/reader.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,7 @@ def initialize(input = $stdin, **options, &block)
8080
@options[:base] ||= input.path if input.respond_to?(:path)
8181
@options[:base] ||= input.filename if input.respond_to?(:filename)
8282
if RDF::URI(@options[:base]).relative? && File.exist?(@options[:base].to_s)
83-
file_uri = if Gem.win_platform?
84-
# Expanded path starts with drive letter
85-
"file:/" + File.expand_path(@options[:base], __FILE__)
86-
else
87-
"file:" + File.expand_path(@options[:base], __FILE__)
88-
end
83+
file_uri = (Gem.win_platform? ? "file:/" : "file:") + @options[:base]
8984
@options[:base] = RDF::URI(file_uri.to_s).normalize
9085
end
9186

0 commit comments

Comments
 (0)