Loading CHANGES.md +19 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,11 @@ Version 1.0.6 To be released. - Fixed default document loaders' incorrect handling of relative URIs in `Link` headers with `rel=alternate`. [[#155] by Emelia Smith] - The `fetchDocumentLoader()` function now preloads the following JSON-LD context: <http://schema.org/>. Version 1.0.5 ------------- Loading Loading @@ -237,6 +242,19 @@ Released on September 26, 2024. [#137]: https://github.com/dahlia/fedify/issues/137 Version 0.15.4 -------------- Released on October 27, 2024. - Fixed default document loaders' incorrect handling of relative URIs in `Link` headers with `rel=alternate`. [[#155] by Emelia Smith] - The `fetchDocumentLoader()` function now preloads the following JSON-LD context: <http://schema.org/>. [#155]: https://github.com/dahlia/fedify/pull/155 Version 0.15.3 -------------- Loading Loading @@ -1795,4 +1813,4 @@ Version 0.1.0 Initial release. Released on March 8, 2024. <!-- cSpell: ignore Dogeon Fabien Wressell --> <!-- cSpell: ignore Dogeon Fabien Wressell Emelia --> src/runtime/contexts.ts +3369 −0 File changed.Preview size limit exceeded, changes collapsed. Show changes src/runtime/docloader.test.ts +39 −0 Original line number Diff line number Diff line Loading @@ -83,6 +83,19 @@ test("fetchDocumentLoader()", async (t) => { }, )); mf.mock("GET@/link-obj-relative", (_req) => new Response( "", { status: 200, headers: { "Content-Type": "text/html; charset=utf-8", Link: '</object>; rel="alternate"; ' + 'type="application/activity+json"', }, }, )); await t.step("Link header", async () => { assertEquals(await fetchDocumentLoader("https://example.com/link-ctx"), { contextUrl: "https://www.w3.org/ns/activitystreams", Loading @@ -106,6 +119,32 @@ test("fetchDocumentLoader()", async (t) => { }); }); await t.step("Link header relative url", async () => { assertEquals(await fetchDocumentLoader("https://example.com/link-ctx"), { contextUrl: "https://www.w3.org/ns/activitystreams", documentUrl: "https://example.com/link-ctx", document: { id: "https://example.com/link-ctx", name: "Fetched object", type: "Object", }, }); assertEquals( await fetchDocumentLoader("https://example.com/link-obj-relative"), { contextUrl: null, documentUrl: "https://example.com/object", document: { "@context": "https://www.w3.org/ns/activitystreams", id: "https://example.com/object", name: "Fetched object", type: "Object", }, }, ); }); mf.mock("GET@/html-link", (_req) => new Response( `<html> Loading src/runtime/docloader.ts +4 −3 Original line number Diff line number Diff line Loading @@ -133,18 +133,19 @@ async function getRemoteDocument( } else { const entries = link.getByRel("alternate"); for (const [uri, params] of entries) { const altUri = new URL(uri, docUrl); if ( "type" in params && (params.type === "application/activity+json" || params.type === "application/ld+json" || params.type.startsWith("application/ld+json;")) && new URL(uri).href !== docUrl.href altUri.href !== docUrl.href ) { logger.debug( "Found alternate document: {alternateUrl} from {url}", { alternateUrl: uri, url: documentUrl }, { alternateUrl: altUri.href, url: documentUrl }, ); return await fetch(uri); return await fetch(altUri.href); } } } Loading Loading
CHANGES.md +19 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,11 @@ Version 1.0.6 To be released. - Fixed default document loaders' incorrect handling of relative URIs in `Link` headers with `rel=alternate`. [[#155] by Emelia Smith] - The `fetchDocumentLoader()` function now preloads the following JSON-LD context: <http://schema.org/>. Version 1.0.5 ------------- Loading Loading @@ -237,6 +242,19 @@ Released on September 26, 2024. [#137]: https://github.com/dahlia/fedify/issues/137 Version 0.15.4 -------------- Released on October 27, 2024. - Fixed default document loaders' incorrect handling of relative URIs in `Link` headers with `rel=alternate`. [[#155] by Emelia Smith] - The `fetchDocumentLoader()` function now preloads the following JSON-LD context: <http://schema.org/>. [#155]: https://github.com/dahlia/fedify/pull/155 Version 0.15.3 -------------- Loading Loading @@ -1795,4 +1813,4 @@ Version 0.1.0 Initial release. Released on March 8, 2024. <!-- cSpell: ignore Dogeon Fabien Wressell --> <!-- cSpell: ignore Dogeon Fabien Wressell Emelia -->
src/runtime/contexts.ts +3369 −0 File changed.Preview size limit exceeded, changes collapsed. Show changes
src/runtime/docloader.test.ts +39 −0 Original line number Diff line number Diff line Loading @@ -83,6 +83,19 @@ test("fetchDocumentLoader()", async (t) => { }, )); mf.mock("GET@/link-obj-relative", (_req) => new Response( "", { status: 200, headers: { "Content-Type": "text/html; charset=utf-8", Link: '</object>; rel="alternate"; ' + 'type="application/activity+json"', }, }, )); await t.step("Link header", async () => { assertEquals(await fetchDocumentLoader("https://example.com/link-ctx"), { contextUrl: "https://www.w3.org/ns/activitystreams", Loading @@ -106,6 +119,32 @@ test("fetchDocumentLoader()", async (t) => { }); }); await t.step("Link header relative url", async () => { assertEquals(await fetchDocumentLoader("https://example.com/link-ctx"), { contextUrl: "https://www.w3.org/ns/activitystreams", documentUrl: "https://example.com/link-ctx", document: { id: "https://example.com/link-ctx", name: "Fetched object", type: "Object", }, }); assertEquals( await fetchDocumentLoader("https://example.com/link-obj-relative"), { contextUrl: null, documentUrl: "https://example.com/object", document: { "@context": "https://www.w3.org/ns/activitystreams", id: "https://example.com/object", name: "Fetched object", type: "Object", }, }, ); }); mf.mock("GET@/html-link", (_req) => new Response( `<html> Loading
src/runtime/docloader.ts +4 −3 Original line number Diff line number Diff line Loading @@ -133,18 +133,19 @@ async function getRemoteDocument( } else { const entries = link.getByRel("alternate"); for (const [uri, params] of entries) { const altUri = new URL(uri, docUrl); if ( "type" in params && (params.type === "application/activity+json" || params.type === "application/ld+json" || params.type.startsWith("application/ld+json;")) && new URL(uri).href !== docUrl.href altUri.href !== docUrl.href ) { logger.debug( "Found alternate document: {alternateUrl} from {url}", { alternateUrl: uri, url: documentUrl }, { alternateUrl: altUri.href, url: documentUrl }, ); return await fetch(uri); return await fetch(altUri.href); } } } Loading