{"record":{"id":"aeb4a0c256427138","repo":"siyuan-note/siyuan","slug":"invalid-encoded-style-entity-in-attribute-view-ric-aeb4a0","errorCode":null,"errorMessage":"invalid encoded style entity in attribute view rich text node [%s]","messagePattern":"invalid encoded style entity in attribute view rich text node \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/value.go","lineNumber":1994,"sourceCode":"\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:\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 {","sourceCodeStart":1976,"sourceCodeEnd":2012,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/value.go#L1976-L2012","documentation":"During sentinel restoration, a node whose raw Tokens contain the sentinel token failed markValueTextRichStyleProtections: the token inside a code block code, math block content, code span, or inline math content is malformed (bad index, missing suffix) or could not be matched against the recorded protections. The restoration is aborted because the entity cannot be safely restored.","triggerScenarios":"Parsing AV rich text where a sentinel token embedded in NodeCodeBlockCode / NodeMathBlockContent / NodeCodeSpanContent / NodeInlineMathContent tokens was truncated or given an index that is not in the protection list (e.g. token 7 when only 5 entities exist).","commonSituations":"Hand-editing or diff-merging .av Kramdown content so tokens were cut mid-way; data written by a mismatched kernel version; corruption during copy of database rows between documents.","solutions":["Restore the original HTML entity in place of the broken token in the code/math content","Re-create the cell value through the UI or API so the sanitizer runs end-to-end","Verify the payload against a known-good copy of the row from history and re-submit it","Check for tooling that does naive string replacement on Kramdown and fix it to preserve tokens intact"],"exampleFix":"// before: broken token in code span content\n`\\ue000siyuan-av-rich-text-style-entities-9` (index out of range)\n// after: literal entity\n`&nbsp;`","handlingStrategy":"validation","validationCode":"// ensure code/math tokens contain only complete tokens or none\nfunction hasCompleteTokens(s, sentinel) {\n  let i = 0;\n  while ((i = s.indexOf(sentinel, i)) !== -1) {\n    if (s.indexOf(\"\\ue002\", i) === -1) return false;\n    i += 1;\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try { saveValue(v) } catch (e) { if (String(e).includes(\"rich text node\")) { restoreFromHistory(v.blockId); } }","preventionTips":["Avoid string surgery on code block / math content that could cut sentinel tokens","Re-type the entity literally instead of copying tokenized intermediates","Use block history to recover after failed writes"],"tags":["attribute-view","rich-text","code-block","sanitization"],"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"}