Resolve relative web app manifest URLs #7
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
manifique (1.1.0)
|
||||
manifique (1.1.1)
|
||||
faraday (~> 2.9.0)
|
||||
faraday-follow_redirects (= 0.3.0)
|
||||
nokogiri (~> 1.16.0)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Manifique
|
||||
VERSION = "1.1.0"
|
||||
VERSION = "1.1.1"
|
||||
end
|
||||
@@ -1,4 +1,5 @@
|
||||
require 'json'
|
||||
require 'uri'
|
||||
require 'faraday'
|
||||
require 'faraday/follow_redirects'
|
||||
require 'nokogiri'
|
||||
@@ -38,8 +39,8 @@ module Manifique
|
||||
return false unless manifest_url = discover_web_manifest_url(@html)
|
||||
|
||||
unless manifest_url.match(/^https?\:\/\//)
|
||||
# Link is just the manifest path, not an absolute URL
|
||||
manifest_url = [@url.gsub(/\/$/, ''), manifest_url.gsub(/^\//, '')].join('/')
|
||||
# Resolve the manifest URL against the document URL (RFC 3986)
|
||||
manifest_url = URI.join(@url, manifest_url).to_s
|
||||
end
|
||||
|
||||
res = do_get_request manifest_url
|
||||
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Relative manifest test page</title>
|
||||
<link rel="manifest" href="./manifest.webmanifest">
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -143,6 +143,46 @@ RSpec.describe Manifique::WebClient do
|
||||
end
|
||||
end
|
||||
|
||||
context "link[rel=manifest] with a relative URL" do
|
||||
before do
|
||||
index_html = File.read(File.join(__dir__, "..", "fixtures", "relative-manifest.html"));
|
||||
stub_request(:get, "https://kosmos.social/").
|
||||
to_return(body: index_html, status: 200, headers: {
|
||||
"Content-Type": "text/html; charset=utf-8"
|
||||
})
|
||||
manifest = File.read(File.join(__dir__, "..", "fixtures", "mastodon-web-app-manifest.json"));
|
||||
stub_request(:get, "https://kosmos.social/manifest.webmanifest").
|
||||
to_return(body: manifest, status: 200, headers: {
|
||||
"Content-Type": "application/manifest+json"
|
||||
})
|
||||
|
||||
web_client.send(:fetch_website)
|
||||
end
|
||||
|
||||
subject do
|
||||
web_client.send(:fetch_web_manifest)
|
||||
end
|
||||
|
||||
it "returns the fetched manifest as a hash" do
|
||||
expect(subject).to be_kind_of(Hash)
|
||||
expect(subject["name"]).to eq("kosmos.social")
|
||||
end
|
||||
|
||||
it "resolves the manifest URL without dot segments" do
|
||||
requested_urls = []
|
||||
allow(web_client).to receive(:do_get_request).and_wrap_original do |original, url|
|
||||
requested_urls << url
|
||||
original.call(url)
|
||||
end
|
||||
|
||||
subject
|
||||
|
||||
expect(requested_urls).to eq(["https://kosmos.social/manifest.webmanifest"])
|
||||
expect(a_request(:get, "https://kosmos.social/manifest.webmanifest")).
|
||||
to have_been_made
|
||||
end
|
||||
end
|
||||
|
||||
context "no link[rel=manifest] element found" do
|
||||
before do
|
||||
index_html = File.read(File.join(__dir__, "..", "fixtures", "mastodon-no-manifest.html"));
|
||||
|
||||
Reference in new issue
Block a user