From 884e3ef780848e6254ab33e5550e82c2a16cfa4b Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Tue, 8 Oct 2024 14:05:06 -0700 Subject: [PATCH] Re-figure File.open_file handling of the file scheme. --- lib/rdf/util/file.rb | 1 - spec/util_file_spec.rb | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/rdf/util/file.rb b/lib/rdf/util/file.rb index 1e5148ae..4f45b45d 100644 --- a/lib/rdf/util/file.rb +++ b/lib/rdf/util/file.rb @@ -297,7 +297,6 @@ def http_adapter(use_net_http = false) # @yieldreturn [Object] returned from open_file # @raise [IOError] if not found def self.open_file(filename_or_url, proxy: nil, headers: {}, verify_none: false, **options, &block) - filename_or_url = $1 if filename_or_url.to_s.match(/^file:(.*)$/) remote_document = nil if filename_or_url.to_s.match?(/^https?/) diff --git a/spec/util_file_spec.rb b/spec/util_file_spec.rb index 9b1ef138..e8d61001 100644 --- a/spec/util_file_spec.rb +++ b/spec/util_file_spec.rb @@ -98,6 +98,17 @@ expect(r).to be_a(RDF::Reader) end + it "yields a file scheme" do + path = fixture_path("test.nt") + path = Gem.win_platform? ? "file:/#{path}" : "file:#{path}" + r = RDF::Util::File.open_file(path) do |f| + expect(f).to respond_to(:read) + opened.opened + RDF::Reader.new + end + expect(r).to be_a(RDF::Reader) + end + it "raises IOError on missing local file" do expect {RDF::Util::File.open_file(fixture_path("not-here"))}.to raise_error IOError opened.opened