Skip to content

hyperlinks.list returns an XML-escaped href for an external link with two query parameters (SDK regression) #4174

Backlog

Description

@ohcedar

Tested on Node.js 24.21.0 with @superdoc/sdk 2.33.0 (native host 0.56.0) and 2.26.0 (native host 0.49.0), docx 9.16.1, jszip 3.10.2. These SDK versions correspond to the SuperDoc 2.36.0 and 2.29.0 release families. The reproduction uses the native headless SDK.

Expected and actual behavior

Create an external hyperlink to https://example.com/?a=1&b=2. Its relationship XML correctly spells the separator &. The public properties.href should return the decoded URL string.

SDK 2.26 returns the decoded URL. SDK 2.33 returns the literal five characters &, so parsing the reported URL produces query parameters a and amp;b instead of a and b. The public href filter also reverses its results: hrefPattern: '&b=2' returns zero links, while hrefPattern: '&b=2' returns one. On 2.26 the totals are one and zero respectively.

The input and post-edit export both escape the relationship target exactly once on both SDKs. Please decode the relationship attribute when representing the URL in the inventory and matching its href.

Standalone reproduction and observed output

Save the following as repro.mjs in an empty directory.

npm install @superdoc/sdk@2.33.0 docx@9.16.1 jszip@3.10.2
node repro.mjs
npm install @superdoc/sdk@2.26.0
node repro.mjs
import { createRequire } from 'node:module';
import { mkdtemp, readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
const require = createRequire(import.meta.url);
const { createSuperDocClient } = require('@superdoc/sdk');
const JSZip = require('jszip');
const { Document, Packer, Paragraph, ExternalHyperlink, TextRun } = require('docx');
const dir = await mkdtemp(join(tmpdir(), 'superdoc-'));
const file = join(dir, 'input.docx');
const part = (zip, name = 'word/document.xml') => zip.file(name).async('string');
const exported = async (doc) =>
  JSZip.loadAsync(Buffer.from((await doc.export.toDocx({})).contentBase64, 'base64'));
const url = 'https://example.com/?a=1&b=2';
const link = new ExternalHyperlink({ link: url, children: [new TextRun('Link')] });
await writeFile(
  file,
  await Packer.toBuffer(new Document({ sections: [{ children: [new Paragraph({ children: [link] })] }] })),
);
const target = async (zip) =>
  (await part(zip, 'word/_rels/document.xml.rels')).match(/Target="(https:[^"]+)"/)[1];
const client = createSuperDocClient({ user: { name: 'Reviewer', email: 'user@example.com' } });
await client.connect();
try {
  const doc = await client.open({ doc: file });
  console.log('URL', url);
  console.log('input relationship XML', await target(await JSZip.loadAsync(await readFile(file))));
  const href = (await doc.hyperlinks.list({})).items[0].properties.href;
  console.log('inventory href', href);
  console.log('parsed search params', [...new URL(href).searchParams.keys()]);
  console.log(
    'real href filter',
    (await doc.hyperlinks.list({ hrefPattern: '&b=2' })).total,
    'escaped href filter',
    (await doc.hyperlinks.list({ hrefPattern: '&b=2' })).total,
  );
  await doc.insert({ value: 'Extra', changeMode: 'direct' });
  console.log('exported relationship XML', await target(await exported(doc)));
  await doc.close({ discard: true });
} finally {
  await client.dispose();
}

Observed output

@superdoc/sdk 2.26.0 (native host 0.49.0)
URL https://example.com/?a=1&b=2
input relationship XML https://example.com/?a=1&b=2
inventory href https://example.com/?a=1&b=2
parsed search params [ 'a', 'b' ]
real href filter 1 escaped href filter 0
exported relationship XML https://example.com/?a=1&b=2

@superdoc/sdk 2.33.0 (native host 0.56.0)
URL https://example.com/?a=1&b=2
input relationship XML https://example.com/?a=1&b=2
inventory href https://example.com/?a=1&b=2
parsed search params [ 'a', 'amp;b' ]
real href filter 0 escaped href filter 1
exported relationship XML https://example.com/?a=1&b=2

Activity

  1. added
    status: triage
    on Nov 27, 2026
  2. added theissue type on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: triage

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions