Ignore inadequate icon sources
Icons with data URLs as source are throwing exceptions when trying to parse their type via the file extension. This fix ignores all icons with data URLs to begin with.
This commit is contained in:
17
spec/fixtures/kommit.html
vendored
Normal file
17
spec/fixtures/kommit.html
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Kommit</title>
|
||||
<meta name="description" content="Augment your memory" />
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
|
||||
<link rel="canonical" href="/" />
|
||||
<link rel="alternate" hreflang="en" href="/en/" />
|
||||
<link rel="apple-touch-icon" href="https://abcdefg.s3.amazonaws.com/public/icon.jpg">
|
||||
</head>
|
||||
<head>
|
||||
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -211,6 +211,38 @@ RSpec.describe Manifique::WebClient do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with data URL icons" do
|
||||
before do
|
||||
index_html = File.read(File.join(__dir__, "..", "fixtures", "kommit.html"));
|
||||
stub_request(:get, "https://kosmos.social/").
|
||||
to_return(body: index_html, status: 200, headers: {
|
||||
"Content-Type": "text/html; charset=utf-8"
|
||||
})
|
||||
end
|
||||
|
||||
subject { web_client.fetch_metadata }
|
||||
|
||||
it "returns a metadata object" do
|
||||
expect(subject).to be_kind_of(Manifique::Metadata)
|
||||
end
|
||||
|
||||
it "loads properties from parsed HTML" do
|
||||
expect(subject.name).to eq("Kommit")
|
||||
expect(subject.description).to eq("Augment your memory")
|
||||
end
|
||||
|
||||
it "ignores data URL icons" do
|
||||
expect(subject.icons.length).to eq(1)
|
||||
end
|
||||
|
||||
it "loads icons from link[rel=apple-touch-icon] elements" do
|
||||
apple_touch_icons = subject.icons.select{|i| i["purpose"] == "apple-touch-icon"}
|
||||
expect(apple_touch_icons.length).to eq(1)
|
||||
expect(apple_touch_icons.first["type"]).to eq("image/jpg")
|
||||
expect(apple_touch_icons.first["sizes"]).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user