{"record":{"id":"8c32aaa3d739ed33","repo":"siyuan-note/siyuan","slug":"invalid-encoded-style-entity-in-attribute-view-ric-8c32aa","errorCode":null,"errorMessage":"invalid encoded style entity in attribute view rich text mark [%s]","messagePattern":"invalid encoded style entity in attribute view rich text mark \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/value.go","lineNumber":1974,"sourceCode":"\t\t\tif !node.IsTextMarkType(\"text\") {\n\t\t\t\terr = fmt.Errorf(\"encoded style entity is not attached to an attribute view rich text span\")\n\t\t\t\treturn ast.WalkStop\n\t\t\t}\n\t\t\tif textProtected || inlineMathProtected || tokensProtected ||\n\t\t\t\t!markValueTextRichStyleProtections(style, sentinel, tokenIndexes, restored) {\n\t\t\t\terr = fmt.Errorf(\"invalid encoded style entity in attribute view rich text span\")\n\t\t\t\treturn ast.WalkStop\n\t\t\t}\n\t\t\tstyle = styleReplacer.Replace(style)\n\t\t\tnode.SetIALAttr(\"style\", style)\n\t\t\tif nil != node.Next && ast.NodeKramdownSpanIAL == node.Next.Type {\n\t\t\t\tnode.Next.Tokens = parse.IAL2Tokens(node.KramdownIAL)\n\t\t\t}\n\t\t\treturn ast.WalkContinue\n\t\t}\n\t\tif textProtected || inlineMathProtected {\n\t\t\tif !node.IsTextMarkType(\"code\") && !node.IsTextMarkType(\"inline-math\") {\n\t\t\t\terr = fmt.Errorf(\"invalid encoded style entity in attribute view rich text mark [%s]\", node.TextMarkType)\n\t\t\t\treturn ast.WalkStop\n\t\t\t}\n\t\t\tif tokensProtected || textProtected &&\n\t\t\t\t!markValueTextRichStyleProtections(node.TextMarkTextContent, sentinel, tokenIndexes, restored) ||\n\t\t\t\tinlineMathProtected &&\n\t\t\t\t\t!markValueTextRichStyleProtections(node.TextMarkInlineMathContent, sentinel, tokenIndexes, restored) {\n\t\t\t\terr = fmt.Errorf(\"invalid encoded style entity in attribute view rich text mark [%s]\", node.TextMarkType)\n\t\t\t\treturn ast.WalkStop\n\t\t\t}\n\t\t\tnode.TextMarkTextContent = textMarkCodeReplacer.Replace(node.TextMarkTextContent)\n\t\t\tnode.TextMarkInlineMathContent = textMarkInlineMathReplacer.Replace(node.TextMarkInlineMathContent)\n\t\t\treturn ast.WalkContinue\n\t\t}\n\t\tif !tokensProtected {\n\t\t\treturn ast.WalkContinue\n\t\t}\n\t\tswitch node.Type {\n\t\tcase ast.NodeCodeBlockCode, ast.NodeMathBlockContent, ast.NodeCodeSpanContent, ast.NodeInlineMathContent:","sourceCodeStart":1956,"sourceCodeEnd":1992,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/value.go#L1956-L1992","documentation":"While restoring HTML style entities that were replaced with sentinel tokens during attribute view rich text sanitization, the walker found a sentinel inside a text mark's content (or inline math content) whose mark type is neither 'code' nor 'inline-math'. Only those mark types are allowed to carry protected entity tokens in their text, so any other mark type containing a sentinel means the rich text payload was hand-crafted or corrupted. The library aborts normalization to prevent style-attribute injection via crafted entity tokens.","triggerScenarios":"Calling NormalizeValueTextRich / NormalizeRichContent (directly or via AV value save/update APIs, e.g. setting a database text cell) with rich text content where an HTML entity such as &#123; or &amp; in the content of a non-code/non-inline-math text mark was converted to a protection sentinel during parsing but appears in a disallowed position, e.g. inside a 'strong', 'em', 'a', or 'tag' text mark's text.","commonSituations":"Programmatically building or post-processing attribute view rich text (plugins, scripts, imports) and inserting raw HTML entities into mark text; editing the .av JSON by hand; corrupted rows after partial sync or a buggy external tool.","solutions":["Remove the raw HTML entity from the text of the offending text mark, or wrap that text in a code (inline code) or inline-math mark where entity tokens are permitted","Re-generate the rich text content through the editor (Protyle DOM -> Kramdown) instead of hand-assembling the Kramdown string","Escape entities in the way the exporter expects (e.g. use literal characters instead of &#...; sequences) and retry the update","Restore the affected row/value from history or backup if the payload was corrupted by an external write"],"exampleFix":"// before: entity inside a bold mark\n{\"type\":\"strong\",\"text\":\"a &#38; b\"}\n// after: entity only in an inline code mark\n{\"type\":\"code\",\"text\":\"a &#38; b\"}","handlingStrategy":"validation","validationCode":"// strip HTML entities from text of non-code/non-inline-math marks before submit\nif (/[&][a-zA-Z]+;|&#\\d+;/.test(markText) && ![\"code\",\"inline-math\"].includes(markType)) {\n  throw new Error(\"entity not allowed in mark type \" + markType);\n}","typeGuard":null,"tryCatchPattern":"try { await setCellValue(rich) } catch (e) { if (String(e.msg).includes(\"invalid encoded style entity\")) { regenerateViaEditorRoundTrip(); } }","preventionTips":["Never hand-assemble AV Kramdown; build content through the editor DOM round-trip","Keep HTML entities only inside inline code or inline math marks","Scan programmatically generated content for &#...; outside code marks before saving"],"tags":["attribute-view","rich-text","sanitization","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}