Skip to content

fix: space single-quoted HTML attribute values - #347

Open
Omair-Asdaq wants to merge 1 commit into
vinta:masterfrom
Omair-Asdaq:fix/single-quoted-attributes
Open

Omair-Asdaq wants to merge 1 commit into
vinta:masterfrom
Omair-Asdaq:fix/single-quoted-attributes

Conversation

@Omair-Asdaq

@Omair-Asdaq Omair-Asdaq commented Nov 7, 2026 •

Copy link
Copy Markdown

Problem

spaceText spaces the text inside HTML attribute values, but the attribute matcher only accepted double-quoted values. A single-quoted value stayed tight while its double-quoted twin was spaced:

pangu.spaceText('<input value="測試123">') // '<input value="測試 123">'
pangu.spaceText("<input value='測試123'>") // '<input value=\'測試123\'>' before this change

CONTEXT.md and docs/adr/0005-bare-unpaired-tags-read-as-mentions.md both say attribute values are spaced, without qualifying the quote style.

Change

The attribute matcher now accepts either quote style and preserves the original delimiter:

const processedTag = match.replace(/(\w+)=("[^"]*"|'[^']*')/g, ...)

The value still goes through spaceText; only the single-quoted path changes. The double-quoted path is byte-identical: 4,003 apostrophe-free inputs, 3,360 double-quoted shapes, and a Private Use Area sweep produced no differences.

Test evidence

  • New dedicated case space single-quoted attribute values in tests/shared/symbol-angle-brackets.test.ts.
  • On baseline it fails at line 50: expected '<input value=\'測試123\'>' to be '<input value=\'測試 123\'>'. With the fix it passes; the other cases stay green.
  • The third assertion (value='say "測試123"') catches a looser mutant that stops the value at either quote character; the shipped regex passes it.
  • npx vitest run tests/: 57 files, 445 passed, 6 expected fail, 0 failed.
  • npx vitest run browser-extensions/chrome/tests/: 10 files, 221 passed.
  • npx tsc --noEmit -p tsconfig.json: clean.
  • npx eslint src/shared/index.ts tests/shared/symbol-angle-brackets.test.ts: clean.
  • npx prettier --check ...: clean.
  • The repository's npm run build/test:shared chains use Unix rm -rf; I ran the equivalent npm run build:lib, the extension vite build, and vitest directly.

Boundary shapes

Input Before After
<input value="測試123"> 測試 123 unchanged
<input value='測試123'> 測試123 測試 123
<input value=''> / value="" unchanged unchanged
<input value="a'b"> / value='a"b' unchanged unchanged
<input value='測試123' data-title='A中文'> mixed both spaced; delimiters preserved
Plain text / no tags unchanged unchanged

A 6,943-input differential matrix produced 212 differences, all inside single-quoted attribute values, with no removed spaces or structural changes. 3,360/3,360 single-vs-double pairs match after normalizing the delimiter; idempotency had 0 violations; a 5,000-input fuzz had 0 throws and 0 unintended differences.

Known limitations

  • Unquoted attribute values (title=測試123), whitespace around =, and a literal > inside a quoted value still follow the existing tag matcher; this PR does not change them.
  • Attribute values are processed as text, so the engine's existing entity/& reading (for example &nbsp;) is unchanged; that behavior predates this PR and needs its own decision.
  • Single-quoted values now participate in hasProperSpacing/pangu -c: an HTML source with <input value='測試123'> that previously exited 0 now reports it as needing correction (exit 1), which is the intended contract.
  • Browser/Playwright suites were not run (browsers unavailable); the DOM path passes text-node data only, and its junction window (at most four characters) cannot contain name='value', so the shared string path is the only affected consumer.

Claim check

No open issue or PR covers this; the repository had 0 open PRs. Prior commits 7a86527 (URL protection) and 266d6e8 (double-quoted attribute values) were inspected; the repro still fails on HEAD, so this is a residual single-quote gap rather than a fixed defect. Evidence: repo-repair-work/vinta-pangu.js-claim.md.

Attribute value spacing matched only double-quoted values, so
`<input value='測試123'>` stayed tight while the double-quoted form
became `<input value="測試 123">`. Match either quote style and preserve
the original delimiter. Add regression cases to the angle-bracket suite.
@Omair-Asdaq
Omair-Asdaq marked this pull request as ready for review November 7, 2026 00:22
Copilot AI balanced review requested due to automatic review settings November 7, 2026 00:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants