Skip to content

Commit 7d0ad9c

Browse files
committed
In Reader.open, ignore content_type if it is 'text/plain'. This allows us to fall back on file_name and/or sampling.
1 parent 1b20f42 commit 7d0ad9c

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/rdf/reader.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ def self.open(filename, format: nil, **options, &block)
207207

208208
Util::File.open_file(filename, options) do |file|
209209
format_options = options.dup
210-
format_options[:content_type] ||= file.content_type if file.respond_to?(:content_type)
210+
format_options[:content_type] ||= file.content_type if
211+
file.respond_to?(:content_type) &&
212+
!file.content_type.to_s.include?('text/plain')
211213
format_options[:file_name] ||= filename
212214
reader = if self == RDF::Reader
213215
# We are the abstract reader class, find an appropriate reader

spec/reader_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,20 @@
7171
reader_mock.got_here
7272
end
7373
end
74+
75+
it "ignores content type 'text/plain'" do
76+
uri = "http://example/foo.ttl"
77+
accept = (RDF::Format.accept_types + %w(*/*;q=0.1)).join(", ")
78+
reader_mock = double("reader")
79+
expect(reader_mock).to receive(:got_here)
80+
WebMock.
81+
stub_request(:get, uri).
82+
to_return(body: "foo", status: 200, headers: { 'Content-Type' => 'text/plain'})
83+
84+
described_class.open(uri) do |r|
85+
expect(r).to be_a(RDF::Turtle::Reader)
86+
reader_mock.got_here
87+
end
88+
end
7489
end
7590
end

0 commit comments

Comments
 (0)