Repository navigation
fix(core): drop a text style a browser would split differently from the filter - #8658
Conversation
terencecho
left a comment
There was a problem hiding this comment.
[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)
Edit accuracy: accurate 273 (base branch 271), smooth 40 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
Quarantined, measured but not gated (0) |
|
Fixed in 7d0ef00. The resource-function check ( |
terencecho
left a comment
There was a problem hiding this comment.
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)
What
The rich-text style filter now drops a whole
styleattribute 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 callimage(),image-set(),src(),cross-fade()orelement(), next to the existingurl(.Why
The splitter tracked quotes inside
/* */comments and ignored escapes and newlines, socolor: red /* ' */; position: fixedwas read as onecolordeclaration and kept whole, while a browser readsposition: fixedas 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
splitDeclarationsinpackages/core/src/utils/richTextSanitize.tsfirst 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 asproperty: valuefrom the split, as before. The editor never writes any of the refused forms, so normal formatting is unchanged.Test plan
fails without the fix:
keeps nothing a browser reads past %sinpackages/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'srichTextSanitize.ts: 8 failed / 62 passed. With the fix:richTextSanitize.test.ts70 passed,runtime/editing/textEdit.test.ts17,runtime/editing/editElement.test.ts12,studio-serversourceMutation.richText.test.ts15 andsourceMutation.test.ts74 pass.