From 14d6af0886e29ead57854fd8b404cec2916cd074 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Wed, 9 Oct 2024 12:11:51 -0700 Subject: [PATCH] Don't expand paths relative to __FILE__ in metadata and reader. --- lib/rdf/tabular/metadata.rb | 11 +++-------- lib/rdf/tabular/reader.rb | 7 +------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/rdf/tabular/metadata.rb b/lib/rdf/tabular/metadata.rb index acccda2..bf693e9 100644 --- a/lib/rdf/tabular/metadata.rb +++ b/lib/rdf/tabular/metadata.rb @@ -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 diff --git a/lib/rdf/tabular/reader.rb b/lib/rdf/tabular/reader.rb index 47b02f7..30d5790 100644 --- a/lib/rdf/tabular/reader.rb +++ b/lib/rdf/tabular/reader.rb @@ -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