Skip to content

Commit 96a5322

Browse files
committed
Correct behaviors for open_file:
* charset should be a downcased string. * content_encoding reflects Content-Encoding, as an array of downcased strings. * Non-UTF input is transformed to UTF-8, so that `external_encoding` is now "utf-8" with `charset` the original character set.
1 parent 7d87245 commit 96a5322

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

lib/rdf/spec/http_adapter.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,28 @@
6464
WebMock.stub_request(:get, uri).to_return(body: "foo", headers: {"Content-Type" => "text/turtle"})
6565
RDF::Util::File.open_file(uri) do |f|
6666
expect(f.content_type).to eq "text/turtle"
67-
expect(f.charset).to eq Encoding::UTF_8
68-
expect(f.content_encoding).to eq "utf-8"
67+
expect(f.charset).to eq "utf-8"
6968
expect(f.external_encoding.to_s.downcase).to eq "utf-8"
7069
opened.opened
7170
end
7271
end
7372

74-
it "sets content_type and encoding if provided" do
75-
WebMock.stub_request(:get, uri).to_return(body: "foo", headers: {"Content-Type" => "text/turtle ; charset=ISO-8859-4"})
73+
it "sets content_type and encoding if provided and UTF" do
74+
WebMock.stub_request(:get, uri).to_return(body: "foo".force_encoding("UTF-16"), headers: {"Content-Type" => "text/turtle ; charset=UTF-16"})
7675
RDF::Util::File.open_file(uri) do |f|
7776
expect(f.content_type).to eq "text/turtle"
78-
expect(f.charset).to eq "ISO-8859-4"
79-
expect(f.external_encoding.to_s.downcase).to eq "iso-8859-4"
77+
expect(f.charset).to eq "utf-16"
78+
expect(f.external_encoding.to_s.downcase).to eq "utf-16"
79+
opened.opened
80+
end
81+
end
82+
83+
it "sets content_type and encoding to UTF-8 if provided and not UTF" do
84+
WebMock.stub_request(:get, uri).to_return(body: "foo".force_encoding("ISO-8859-4"), headers: {"Content-Type" => "text/turtle ; charset=ISO-8859-4"})
85+
RDF::Util::File.open_file(uri) do |f|
86+
expect(f.content_type).to eq "text/turtle"
87+
expect(f.charset).to eq "iso-8859-4"
88+
expect(f.external_encoding.to_s.downcase).to eq "utf-8"
8089
opened.opened
8190
end
8291
end

0 commit comments

Comments
 (0)