{"record":{"id":"c5dbd8ab2d0b5c8d","repo":"wmjordan/PDFPatcher","slug":"error-c5dbd8","errorCode":null,"errorMessage":"“[]”筛选表达式前缺少节点轴及节点名称标识。","messagePattern":"“\\[\\]”筛选表达式前缺少节点轴及节点名称标识。","errorType":"validation","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"App/Model/PdfPath/PathCompiler.cs","lineNumber":48,"sourceCode":"\t\t\tstring n;\r\n\t\t\tvar ctx = new Context();\r\n\t\t\twhile (i < l) {\r\n\t\t\t\tctx.Axis = ExtractAxis(path, l, ctx.CanBeRoot, ref i);\r\n\t\t\t\tif (ctx.Axis == PathAxisType.Root) {\r\n\t\t\t\t\tctx.CanBeRoot = false;\r\n\t\t\t\t\tr.Enqueue(new PathExpression(ctx.Axis));\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tn = ExtractName(path, l, ref i);\r\n\t\t\t\tr.Enqueue(new PathExpression(ctx.Axis, n));\r\n\t\t\t}\r\n\t\t\treturn r.ToArray();\r\n\t\t}\r\n\r\n\t\tprivate static PathAxisType ExtractAxis(string path, int length, bool canBeRoot, ref int index) {\r\n\t\t\tchar c = path[index];\r\n\t\t\tif (__PredicateChars.Contains(c)) {\r\n\t\t\t\tthrow new FormatException(\"“[]”筛选表达式前缺少节点轴及节点名称标识。\");\r\n\t\t\t}\r\n\r\n\t\t\tif (c == PathSeparator) {\r\n\t\t\t\tif (MatchNextChar(path, length, index, PathSeparator)) {\r\n\t\t\t\t\t++index;\r\n\t\t\t\t\treturn PathAxisType.Descendants;\r\n\t\t\t\t}\r\n\t\t\t\telse if (canBeRoot) {\r\n\t\t\t\t\treturn PathAxisType.Root;\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\treturn PathAxisType.Children;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse if (c == SelfChar) {\r\n\t\t\t\tif (MatchNextChar(path, length, index, SelfChar)) {\r\n\t\t\t\t\t++index;\r\n\t\t\t\t\treturn PathAxisType.Parent;\r","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/wmjordan/PDFPatcher/blob/4782bbd9ada850b56258f29999b7a1c9076c9b1b/App/Model/PdfPath/PathCompiler.cs#L30-L66","documentation":"PathCompiler.ExtractAxis throws FormatException when the current path character is '[' or ']' (the predicate delimiters) at a position where an axis separator or node name was expected. In the PDFPath mini-language, a predicate '[...]' must follow a node name or axis; encountering a bracket where an axis is required means the path string is malformed.","triggerScenarios":"Calling PathCompiler.Compile with a path that begins with or otherwise places a '[' before any node name or axis, e.g. \"[1]\" or \"/[1]\". The loop in Compile calls ExtractAxis first, and a leading bracket trips __PredicateChars.Contains(c).","commonSituations":"Programmatically building a path string and forgetting to prepend the node name before a filter; user-entered PDFPath expression with a missing element name; a template substitution that left an empty name before a predicate.","solutions":["Ensure every '[...]' predicate is preceded by a node name or axis (e.g. 'Page[1]' not '[1]').","Validate the path string with a regex or a dry-run compile before using it for selection.","If building paths dynamically, always concatenate the element name before appending the predicate."],"exampleFix":"// before\nvar expr = PathCompiler.Compile(\"[1]\");\n\n// after\nvar expr = PathCompiler.Compile(\"Page[1]\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(path) || path[0] == '[' || path[0] == ']')\n    throw new ArgumentException(\"Path must start with a node name or axis.\");","typeGuard":"static bool IsValidPathStart(string p) => !string.IsNullOrEmpty(p) && p[0] != '[' && p[0] != ']';","tryCatchPattern":"try { var e = PathCompiler.Compile(path); }\ncatch (FormatException ex) { /* malformed path */ }","preventionTips":["Always prefix predicates with a node name or axis.","Dry-run compile paths built from user/template input."],"tags":["validation","pdfpath","format","parsing"],"backgroundTag":null,"analyzedSha":"4782bbd9ada850b56258f29999b7a1c9076c9b1b","analyzedAt":"2026-08-13T17:44:50.812Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}