Skip to content

Commit

Permalink
Don't expand paths relative to __FILE__ in metadata and reader.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Oct 9, 2024
1 parent d0709b4 commit 14d6af0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
11 changes: 3 additions & 8 deletions lib/rdf/tabular/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,9 @@ def self.open(path, **options)
'Accept' => 'application/ld+json, application/json'
}
)
if RDF::URI(path).relative?
path = if Gem.win_platform?
# Expanded path starts with drive letter
"file:/" + File.expand_path(path, __FILE__)
else
"file:#{File.expand_path(path, __FILE__)}"
end
end

# Resolve relative paths to use the file scheme, bearing in mind that Windows expanded paths always start with a drive letter, not a slash.
path = (Gem.win_platform? ? "file:/" : "file:") + File.expand_path(path) if RDF::URI(path).relative?
RDF::Util::File.open_file(path, **options) do |file|
self.new(file, **options.merge(base: path, filenames: path))
end
Expand Down
7 changes: 1 addition & 6 deletions lib/rdf/tabular/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ def initialize(input = $stdin, **options, &block)
@options[:base] ||= input.path if input.respond_to?(:path)
@options[:base] ||= input.filename if input.respond_to?(:filename)
if RDF::URI(@options[:base]).relative? && File.exist?(@options[:base].to_s)
file_uri = if Gem.win_platform?
# Expanded path starts with drive letter
"file:/" + File.expand_path(@options[:base], __FILE__)
else
"file:" + File.expand_path(@options[:base], __FILE__)
end
file_uri = (Gem.win_platform? ? "file:/" : "file:") + @options[:base]
@options[:base] = RDF::URI(file_uri.to_s).normalize
end

Expand Down

0 comments on commit 14d6af0

Please sign in to comment.