Resolve relative web app manifest URLs #7

Merged
raucao merged 2 commits from fix/relative-manifest-url into master 2026-11-23 18:41:24 +00:00
5 changed files with 55 additions and 4 deletions

No files matched your search

+1 -1
View File
@@ -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 -1
View File
@@ -1,3 +1,3 @@
module Manifique
VERSION = "1.1.0"
VERSION = "1.1.1"
end
+3 -2
View File
@@ -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
+10
View File
@@ -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>
+40
View File
@@ -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"));