Skip to content

fix(muya): align normalizePastedHTML link unlinking with muyajs - #4550

Merged
Jocs merged 1 commit into
developfrom
fix/clipboard-normalize-html
Jun 18, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/clipboard-normalize-html

Conversation

@Jocs

@Jocs Jocs commented Jun 17, 2026

Copy link
Copy Markdown
Member

Two divergences in the <a>-unlinking pass of normalizePastedHTML
(packages/muya/src/utils/paste.ts) versus legacy muyajs
(pasteCtrl.normalizePastedHTML):

  1. Missing URL_REG guard. muyajs unlinks a bare URL only when
    URL_REG.test(href) && href === text. muya checked just href === text, so
    any link whose visible text happened to equal its href — even a non-URL like
    <a href="foo">foo</a> — was stripped to a bare span. Restore the URL guard
    so only real bare-URL links are unlinked.
  2. Unescaped fallback span. When no page title resolves, the fallback set
    span.innerHTML = text raw; muyajs escapes + sanitizes via
    sanitize(text, PREVIEW_DOMPURIFY_CONFIG, true). Match it so a stray angle
    bracket in the link text can't re-enter as live markup.

Tests

New src/utils/__tests__/normalizePastedHtml.spec.ts (RED→GREEN verified):
non-URL link preserved, differing-text link preserved, bare-URL link unlinked to
an escaped span when offline. 141/141 utils specs green; typecheck clean.

Independent of the clipboard paste stack (touches only utils/paste.ts).

🤖 Generated with Claude Code

Two divergences in the `<a>`-unlinking pass of normalizePastedHTML:

- The guard was `href === text` without muyajs's `URL_REG.test(href)`, so any
  link whose visible text happened to equal its href — even a non-URL like
  `<a href="foo">foo</a>` — was stripped to a bare span. Restore the URL_REG
  guard so only real bare-URL links are unlinked.
- The fallback span set `innerHTML = text` raw; muyajs escapes + sanitizes via
  `sanitize(text, PREVIEW_DOMPURIFY_CONFIG, true)`. Match it so a stray angle
  bracket in the link text can't re-enter as live markup.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Jocs
Jocs force-pushed the fix/clipboard-normalize-html branch from ed38455 to 15849b8 Compare June 18, 2026 07:55
@Jocs
Jocs merged commit 67a3fee into develop Jun 18, 2026
7 checks passed
@Jocs
Jocs deleted the fix/clipboard-normalize-html branch June 18, 2026 08:13
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.

1 participant