Unverified Commit db326fd8 authored by Hong Minhee's avatar Hong Minhee
Browse files

Fix XHTML self-closing link tag parsing in ActivityPub Discovery

The HTML/XHTML parser now correctly recognizes self-closing <link> tags
with whitespace before the closing slash (/>) in XHTML documents. This
improves compatibility with XHTML documents that follow proper self-closing
tag format for ActivityPub Discovery.
parent 70309729
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -8,6 +8,11 @@ Version 1.0.27

To be released.

 -  Fixed a bug where ActivityPub Discovery failed to recognize XHTML
    self-closing `<link>` tags. The HTML/XHTML parser now correctly handles
    whitespace before the self-closing slash (`/>`), improving compatibility
    with XHTML documents that follow the self-closing tag format.


Version 1.0.26
--------------
+30 −0
Original line number Diff line number Diff line
@@ -209,6 +209,36 @@ test("fetchDocumentLoader()", async (t) => {
    });
  });

  mf.mock("GET@/xhtml-link", (_req) =>
    new Response(
      `<html>
          <head>
            <meta charset=utf-8>
            <link
              rel=alternate
              type="application/activity+json"
              href="https://example.com/object" />
          </head>
        </html>`,
      {
        status: 200,
        headers: { "Content-Type": "application/xhtml+xml; charset=utf-8" },
      },
    ));

  await t.step("XHTML <link>", async () => {
    assertEquals(await fetchDocumentLoader("https://example.com/xhtml-link"), {
      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-a", (_req) =>
    new Response(
      `<html>
+2 −1
Original line number Diff line number Diff line
@@ -166,7 +166,8 @@ async function getRemoteDocument(
      contentType === "application/xhtml+xml" ||
      contentType?.startsWith("application/xhtml+xml;"))
  ) {
    const p = /<(a|link)((\s+[a-z][a-z:_-]*=("[^"]*"|'[^']*'|[^\s>]+))+)\/?>/ig;
    const p =
      /<(a|link)((\s+[a-z][a-z:_-]*=("[^"]*"|'[^']*'|[^\s>]+))+)\s*\/?>/ig;
    const p2 = /\s+([a-z][a-z:_-]*)=("([^"]*)"|'([^']*)'|([^\s>]+))/ig;
    const html = await response.text();
    let m: RegExpExecArray | null;