{"record":{"id":"845a1be9c204379e","repo":"siyuan-note/siyuan","slug":"task-list-item-marker-length-should-be-1","errorCode":null,"errorMessage":"task list item marker length should be 1","messagePattern":"task list item marker length should be 1","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/api/block_op.go","lineNumber":59,"sourceCode":"\t\treturn \"\", errors.New(\"block is not a list item\")\n\t}\n\n\ttree, err := filesys.LoadTree(block.Box, block.Path, luteEngine)\n\tif err != nil {\n\t\treturn \"\", errors.New(\"load tree failed: \" + err.Error())\n\t}\n\n\tli := treenode.GetNodeInTree(tree, id)\n\tif li == nil {\n\t\treturn \"\", errors.New(\"block not found\")\n\t}\n\n\tif 3 != li.ListData.Typ {\n\t\treturn \"\", errors.New(\"block is not a task list item\")\n\t}\n\n\tif 1 != len(marker) {\n\t\treturn \"\", errors.New(\"task list item marker length should be 1\")\n\t}\n\n\tliMarker := marker[0]\n\tif '[' == liMarker || ']' == liMarker {\n\t\treturn \"\", errors.New(\"task list item marker can not be [ or ]\")\n\t}\n\n\tmarkerNode := li.ChildByType(ast.NodeTaskListItemMarker)\n\tif nil == markerNode {\n\t\treturn \"\", errors.New(\"task list item marker not found\")\n\t}\n\n\tmarkerNode.TaskListItemMarker = liMarker\n\tmarkerNode.TaskListItemChecked = ' ' != markerNode.TaskListItemMarker\n\n\ttreenode.RefreshUpdated(li)\n\n\treturn luteEngine.RenderNodeBlockDOM(li), nil","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/api/block_op.go#L41-L77","documentation":"The marker parameter must be exactly one character: 'x' (checked), ' ' (unchecked), or another allowed single character. buildUpdatedTaskListItemBlockDOM rejects any marker string whose length is not 1 before inspecting the block, since a checkbox marker in Markdown is a single character inside [ ].","triggerScenarios":"Calling POST /api/block/updateTaskListItemMarker with marker set to \"x \", \"[x]\", \"xx\", \"\", or a whole Markdown checkbox snippet instead of the single character.","commonSituations":"Clients concatenating the brackets with the mark; trimming bugs that leave whitespace; UI code passing \"checked\"/\"true\" instead of 'x'; batch items where one marker string was built by joining values.","solutions":["Send exactly one character: marker:'x' for checked, marker:' ' (single space) for unchecked","Strip surrounding brackets/whitespace client-side before calling the API: marker = raw.replace(/[\\[\\]\\s]/g, '') and validate length === 1","Map boolean state to the marker character: state ? 'x' : ' '","Add client-side validation that rejects any marker whose length !== 1 before the request"],"exampleFix":"// before\nawait fetchPost('/api/block/updateTaskListItemMarker', { id, marker: '[x]' });\n// after\nconst marker = checked ? 'x' : ' ';\nif (marker.length !== 1) throw new Error('marker must be a single character');\nawait fetchPost('/api/block/updateTaskListItemMarker', { id, marker });","handlingStrategy":"validation","validationCode":"if (typeof marker !== 'string' || marker.length !== 1) {\n  throw new Error(`marker must be a single character, got ${JSON.stringify(marker)}`);\n}","typeGuard":"const isValidMarker = (m) => typeof m === 'string' && m.length === 1 && m !== '[' && m !== ']';","tryCatchPattern":"try {\n  await fetchPost('/api/block/updateTaskListItemMarker', { id, marker });\n} catch (e) {\n  if (String(e?.msg).includes('marker length should be 1')) {\n    const fixed = String(e.input ?? marker).replace(/[\\[\\]\\s]/g, '').slice(0, 1);\n    if (fixed) return fetchPost('/api/block/updateTaskListItemMarker', { id, marker: fixed });\n  }\n  throw e;\n}","preventionTips":["Map booleans to 'x'/' ' at one central helper instead of passing raw strings","Strip brackets/whitespace from any user- or DOM-derived marker input","Add an assertion in shared request helpers that marker.length === 1"],"tags":["validation","invalid-argument","siyuan","task-list"],"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"}