{"record":{"id":"1453fae0c2b77c79","repo":"siyuan-note/siyuan","slug":"attribute-view-rich-text-style-entity-was-not-rest","errorCode":null,"errorMessage":"attribute view rich text style entity was not restored","messagePattern":"attribute view rich text style entity was not restored","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/value.go","lineNumber":2009,"sourceCode":"\t\tswitch node.Type {\n\t\tcase ast.NodeCodeBlockCode, ast.NodeMathBlockContent, ast.NodeCodeSpanContent, ast.NodeInlineMathContent:\n\t\t\tif !markValueTextRichStyleProtections(tokens, sentinel, tokenIndexes, restored) {\n\t\t\t\terr = fmt.Errorf(\"invalid encoded style entity in attribute view rich text node [%s]\", node.Type.String())\n\t\t\t\treturn ast.WalkStop\n\t\t\t}\n\t\t\tnode.Tokens = []byte(literalReplacer.Replace(tokens))\n\t\tdefault:\n\t\t\terr = fmt.Errorf(\"invalid encoded style entity in attribute view rich text node [%s]\", node.Type.String())\n\t\t\treturn ast.WalkStop\n\t\t}\n\t\treturn ast.WalkContinue\n\t})\n\tif nil != err {\n\t\treturn\n\t}\n\tfor _, found := range restored {\n\t\tif !found {\n\t\t\treturn fmt.Errorf(\"attribute view rich text style entity was not restored\")\n\t\t}\n\t}\n\tast.Walk(tree.Root, func(node *ast.Node, entering bool) ast.WalkStatus {\n\t\tif entering && valueTextRichNodeContainsSentinel(node, sentinel) {\n\t\t\terr = fmt.Errorf(\"attribute view rich text style entity sentinel was not removed from node [%s]\",\n\t\t\t\tnode.Type.String())\n\t\t\treturn ast.WalkStop\n\t\t}\n\t\treturn ast.WalkContinue\n\t})\n\treturn\n}\n\nfunc valueTextRichNodeContainsSentinel(node *ast.Node, sentinel string) bool {\n\tvalues := []string{\n\t\tnode.ID, node.Spec, node.Data, string(node.Tokens), string(node.CodeBlockOpenFence),\n\t\tstring(node.CodeBlockInfo), string(node.CodeBlockCloseFence), string(node.LinkRefLabel),\n\t\tstring(node.FootnotesRefLabel), node.FootnotesRefId, string(node.HtmlEntityTokens),","sourceCodeStart":1991,"sourceCodeEnd":2027,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/value.go#L1991-L2027","documentation":"After walking the tree and replacing all sentinel tokens, the sanitizer checked its 'restored' flags and found at least one recorded protection whose token never appeared anywhere in the parsed tree. The content claims to contain a protected HTML entity (the protection list was built) but the corresponding token vanished during parsing, so restoration is incomplete and the library refuses to proceed.","triggerScenarios":"Parsing AV rich text where Lute's parser dropped or merged a token (e.g. the sentinel ended up in a position that is discarded during parsing, such as inside an HTML comment or an invalid construct) so its token index is never marked restored.","commonSituations":"Content where an HTML entity sits inside a construct the parser drops (comments, invalid markup, escaped constructs); content produced by an incompatible writer version; regex edits that moved the token outside the tree.","solutions":["Inspect the rich text source for entities inside constructs that the parser discards (comments, unknown tags) and move the entity into valid inline content","Rebuild the content via the editor round-trip so tokens are regenerated in parseable positions","Upgrade/verify the kernel version used to write the payload matches the one reading it","Restore the affected value from history or backup"],"exampleFix":"// before: entity hidden in a dropped construct\n<!-- a &amp; b -->\n// after: entity in normal text\n\"a &amp; b\"","handlingStrategy":"validation","validationCode":"// avoid entities inside constructs the parser drops (comments, unknown tags)\nif (/<!--[\\s\\S]*?&[a-zA-Z#0-9]+;[\\s\\S]*?-->/.test(content)) {\n  throw new Error(\"HTML entity inside a comment will not survive parsing\");\n}","typeGuard":null,"tryCatchPattern":"try { NormalizeRichContent() } catch (e) { if (String(e).includes(\"was not restored\")) { rebuildContentFromPlainText(); } }","preventionTips":["Place entities in normal inline text, not comments or discarded constructs","Write content through the editor so tokens land in parseable positions","Keep writer/reader kernel versions in sync"],"tags":["attribute-view","rich-text","sanitization","parsing"],"backgroundTag":"internal-invariant-violation","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"}