Skip to content

fix(core): drop a text style a browser would split differently from the filter - #8658

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/rich-text-style-parse
Nov 24, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/rich-text-style-parse

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

The rich-text style filter now drops a whole style attribute when the text holds anything its declaration split would read differently from a browser: a CSS comment, a backslash escape, a string broken by a newline or the end of the text, a stray quote, {}/[], or unbalanced parentheses. It also refuses values that call image(), image-set(), src(), cross-fade() or element(), next to the existing url(.

Why

The splitter tracked quotes inside /* */ comments and ignored escapes and newlines, so color: red /* ' */; position: fixed was read as one color declaration and kept whole, while a browser reads position: fixed as its own declaration. Text edits from a preview frame, generated text and the server's rich-text write all go through this filter, so anything it misreads is saved into the composition file.

Related work

None.

How

splitDeclarations in packages/core/src/utils/richTextSanitize.ts first masks every plain string (no escape, no newline), then refuses the text if what is left holds an escape, a quote, a comment start or a bracket, or if a parenthesis is unbalanced or holds a semicolon. What remains splits on ; exactly where CSS does. When the split refuses, the style attribute is removed and the text keeps its words. Each kept declaration is written back as property: value from the split, as before. The editor never writes any of the refused forms, so normal formatting is unchanged.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

fails without the fix: keeps nothing a browser reads past %s in packages/core/src/utils/richTextSanitize.test.ts (a quote inside a comment, a string broken by a newline, an escaped function name, a string-argument image function; jsdom and linkedom). With main's richTextSanitize.ts: 8 failed / 62 passed. With the fix: richTextSanitize.test.ts 70 passed, runtime/editing/textEdit.test.ts 17, runtime/editing/editElement.test.ts 12, studio-server sourceMutation.richText.test.ts 15 and sourceMutation.test.ts 74 pass.

@terencecho terencecho 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.

[P2] Preserve quoted font names. In packages/core/src/utils/richTextSanitize.ts:88–89,108–113, the expanded function check also scans inside quoted strings. A plain font family named "Image(Display)" is treated as an image function. In an inert LinkeDOM document, the parent kept that family and the accompanying color, while this head kept only the color. Limit the new image-function checks to actual function tokens outside strings. Cover a quoted family alongside the existing function-rejection case.

The PR body names the fail-first test. At review time, the support check was red in catalog generation and other checks were still running.

— tai (automated review)

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 40 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Quarantined, measured but not gated (0)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed in 7d0ef00. The resource-function check (url(, image(, image-set(, src(, cross-fade(, element(, expression() now runs on the value with its plain quoted strings masked, so font-family: "Image(Display)" is kept with its colour. An unquoted image-set("x.png") is still refused. javascript:, @import and </ are still checked on the raw text. New test: keeps a quoted font family whose name reads like a function in packages/core/src/utils/richTextSanitize.test.ts. It fails at f07a5fc (2 failed, jsdom and linkedom) and passes here (72 passed).

@terencecho terencecho 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.

The resource-function check now masks plain quoted strings before matching. I verified that a quoted Image(Display) font family is preserved at this head and rejected at f07a5fc1. The existing fail-first sanitizer coverage remains named in the PR body. CI was still running.

— tai (automated review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 2fee394 Nov 24, 2026
99 checks passed
@miguel-heygen
miguel-heygen deleted the fix/rich-text-style-parse branch November 24, 2026 09:02
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