Loading CHANGES.md +5 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,11 @@ Version 1.0.13 To be released. - Fixed the default document loader to handle the `Link` header with incorrect syntax. [[#196]] [#196]: https://github.com/dahlia/fedify/issues/196 Version 1.0.12 -------------- Loading src/runtime/docloader.test.ts +34 −0 Original line number Diff line number Diff line Loading @@ -96,6 +96,24 @@ test("fetchDocumentLoader()", async (t) => { }, )); mf.mock("GET@/obj-w-wrong-link", (_req) => new Response( JSON.stringify({ "@context": "https://www.w3.org/ns/activitystreams", id: "https://example.com/obj-w-wrong-link", name: "Fetched object", type: "Object", }), { status: 200, headers: { "Content-Type": "text/html; charset=utf-8", Link: '<https://example.com/object>; rel="alternate"; ' + 'type="application/ld+json; profile="https://www.w3.org/ns/activitystreams""', }, }, )); await t.step("Link header", async () => { assertEquals(await fetchDocumentLoader("https://example.com/link-ctx"), { contextUrl: "https://www.w3.org/ns/activitystreams", Loading Loading @@ -145,6 +163,22 @@ test("fetchDocumentLoader()", async (t) => { ); }); await t.step("wrong Link header syntax", async () => { assertEquals( await fetchDocumentLoader("https://example.com/obj-w-wrong-link"), { contextUrl: null, documentUrl: "https://example.com/obj-w-wrong-link", document: { "@context": "https://www.w3.org/ns/activitystreams", id: "https://example.com/obj-w-wrong-link", name: "Fetched object", type: "Object", }, }, ); }); mf.mock("GET@/html-link", (_req) => new Response( `<html> Loading src/runtime/docloader.ts +10 −1 Original line number Diff line number Diff line Loading @@ -121,7 +121,16 @@ async function getRemoteDocument( const linkHeader = response.headers.get("Link"); let contextUrl: string | null = null; if (linkHeader != null) { const link = new HTTPHeaderLink(linkHeader); let link: HTTPHeaderLink; try { link = new HTTPHeaderLink(linkHeader); } catch (e) { if (e instanceof SyntaxError) { link = new HTTPHeaderLink(); } else { throw e; } } if (jsonLd) { const entries = link.getByRel("http://www.w3.org/ns/json-ld#context"); for (const [uri, params] of entries) { Loading Loading
CHANGES.md +5 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,11 @@ Version 1.0.13 To be released. - Fixed the default document loader to handle the `Link` header with incorrect syntax. [[#196]] [#196]: https://github.com/dahlia/fedify/issues/196 Version 1.0.12 -------------- Loading
src/runtime/docloader.test.ts +34 −0 Original line number Diff line number Diff line Loading @@ -96,6 +96,24 @@ test("fetchDocumentLoader()", async (t) => { }, )); mf.mock("GET@/obj-w-wrong-link", (_req) => new Response( JSON.stringify({ "@context": "https://www.w3.org/ns/activitystreams", id: "https://example.com/obj-w-wrong-link", name: "Fetched object", type: "Object", }), { status: 200, headers: { "Content-Type": "text/html; charset=utf-8", Link: '<https://example.com/object>; rel="alternate"; ' + 'type="application/ld+json; profile="https://www.w3.org/ns/activitystreams""', }, }, )); await t.step("Link header", async () => { assertEquals(await fetchDocumentLoader("https://example.com/link-ctx"), { contextUrl: "https://www.w3.org/ns/activitystreams", Loading Loading @@ -145,6 +163,22 @@ test("fetchDocumentLoader()", async (t) => { ); }); await t.step("wrong Link header syntax", async () => { assertEquals( await fetchDocumentLoader("https://example.com/obj-w-wrong-link"), { contextUrl: null, documentUrl: "https://example.com/obj-w-wrong-link", document: { "@context": "https://www.w3.org/ns/activitystreams", id: "https://example.com/obj-w-wrong-link", name: "Fetched object", type: "Object", }, }, ); }); mf.mock("GET@/html-link", (_req) => new Response( `<html> Loading
src/runtime/docloader.ts +10 −1 Original line number Diff line number Diff line Loading @@ -121,7 +121,16 @@ async function getRemoteDocument( const linkHeader = response.headers.get("Link"); let contextUrl: string | null = null; if (linkHeader != null) { const link = new HTTPHeaderLink(linkHeader); let link: HTTPHeaderLink; try { link = new HTTPHeaderLink(linkHeader); } catch (e) { if (e instanceof SyntaxError) { link = new HTTPHeaderLink(); } else { throw e; } } if (jsonLd) { const entries = link.getByRel("http://www.w3.org/ns/json-ld#context"); for (const [uri, params] of entries) { Loading