{"record":{"id":"a03636d5a6bddd15","repo":"siyuan-note/siyuan","slug":"invalid-av-history-path-s","errorCode":null,"errorMessage":"invalid AV history path [%s]","messagePattern":"invalid AV history path \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":694,"sourceCode":"\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"invalid notebook history path [%s]\", historyPath)\n\t}\n\tparts := strings.Split(filepath.ToSlash(rel), \"/\")\n\tif len(parts) != 2 || !strings.HasSuffix(parts[0], \"-\"+HistoryOpDelete) || !ast.IsNodeIDPattern(parts[1]) ||\n\t\t!gulu.File.IsDir(historyPath) || !filelock.IsExist(filepath.Join(historyPath, \".siyuan\", \"conf.json\")) {\n\t\treturn \"\", fmt.Errorf(\"invalid notebook history path [%s]\", historyPath)\n\t}\n\treturn parts[1], nil\n}\n\nfunc RollbackAttributeViewHistory(historyPath string) (err error) {\n\thistoryPath, err = validateHistoryPath(historyPath)\n\tif err != nil {\n\t\treturn\n\t}\n\t// 验证目标文件必须是 AV 定义文件\n\tif !strings.HasSuffix(historyPath, \".json\") || !strings.Contains(filepath.ToSlash(historyPath), \"/storage/av/\") {\n\t\treturn fmt.Errorf(\"invalid AV history path [%s]\", historyPath)\n\t}\n\n\tfrom := historyPath\n\t// 从路径提取 boxID 判断是否加密笔记本的 AV\n\trelPath := strings.TrimPrefix(filepath.ToSlash(historyPath), filepath.ToSlash(util.HistoryDir))\n\trelPath = strings.TrimPrefix(relPath, \"/\")\n\tpathParts := strings.SplitN(relPath, \"/\", 3)\n\tdata, readErr := filelock.ReadFile(from)\n\tif readErr != nil {\n\t\treturn readErr\n\t}\n\tciphertext := util.IsCiphertext(data)\n\tif ciphertext && (len(pathParts) < 3 || !ast.IsNodeIDPattern(pathParts[1]) || !IsEncryptedBox(pathParts[1])) {\n\t\treturn errors.New(\"encrypted attribute view history is missing valid notebook context\")\n\t}\n\tto := filepath.Join(util.DataDir, \"storage\", \"av\", filepath.Base(historyPath))\n\tif len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {\n\t\tif !ciphertext {","sourceCodeStart":676,"sourceCodeEnd":712,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L676-L712","documentation":"RollbackAttributeViewHistory validates that the supplied history archive path points at an attribute-view definition snapshot before attempting a rollback. The path must end in .json and contain the /storage/av/ segment; otherwise the kernel refuses to treat it as an AV history artifact and returns this error. It guards against rolling back arbitrary files as if they were AV snapshots.","triggerScenarios":"Calling RollbackAttributeViewHistory with a path that is not a .json file, or a path whose slash-normalized form does not contain /storage/av/ (e.g. a document history path, an arbitrary user path, or a path with backslashes on Windows that fails normalization).","commonSituations":"Plugin or script code passes a doc-history path instead of an AV history path; hand-crafted history paths from an older SiYuan version with a different layout; Windows path separators leaking into the check.","solutions":["Pass the exact history path returned by the AV history listing API (a *.json file under history/<timestamp>/storage/av/).","Verify the path ends with .json and its ToSlash form contains /storage/av/ before calling.","If migrating old data, re-derive the path from the history index instead of reusing stored raw paths."],"exampleFix":"// before\nrollbackHistory(\"history/20260101120000/storage/av/20260101120000\")\n// after\nrollbackHistory(\"history/20260101120000/storage/av/20260101120000.json\")","handlingStrategy":"validation","validationCode":"const p = filepath.ToSlash(filepath.Clean(historyPath));\nif (!p.endsWith(\".json\") || !p.includes(\"/storage/av/\")) {\n  throw new Error(\"not an AV history path: \" + p);\n}","typeGuard":"function isAvHistoryPath(p) {\n  const s = filepath.ToSlash(p);\n  return s.endsWith(\".json\") && s.includes(\"/storage/av/\");\n}","tryCatchPattern":null,"preventionTips":["Always take the history path from the AV history listing API, never from user input.","Normalize to forward slashes before validating on Windows.","Keep a smoke test that rolls back a known-good AV snapshot."],"tags":["validation","path","attribute-view","history"],"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"}