{"record":{"id":"de5b9418acc27029","repo":"mozilla/pdf.js","slug":"invalid-token-in-index","errorCode":null,"errorMessage":"Invalid token in index.","messagePattern":"Invalid token in index\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/xfa/formcalc_parser.js","lineNumber":493,"sourceCode":"      const [tok, param] = parser.parse();\n      if (param) {\n        params.push(param);\n      }\n      if (tok.id === TOKEN.rightParen) {\n        return params;\n      } else if (tok.id !== TOKEN.comma) {\n        throw new Error(Errors.params);\n      }\n      parser.reset();\n    }\n  }\n\n  static parseIndex(lexer) {\n    let tok = lexer.next();\n    if (tok.id === TOKEN.times) {\n      tok = lexer.next();\n      if (tok.id !== TOKEN.rightBracket) {\n        throw new Error(Errors.index);\n      }\n      return new AstEveryOccurence();\n    }\n    const [token, expr] = new SimpleExprParser(lexer).parse(tok);\n    if (token.id !== TOKEN.rightBracket) {\n      throw new Error(Errors.index);\n    }\n    return expr;\n  }\n\n  pushOperator(op) {\n    this.flushWithOperator(op);\n    this.operators.push(op);\n    this.last = OPERATOR;\n  }\n\n  pushOperand(op) {\n    this.operands.push(op);","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/xfa/formcalc_parser.js#L475-L511","documentation":"Thrown by SimpleExprParser.parseIndex() in the XFA FormCalc parser when an array index uses the wildcard form '[*]' but the '*' is not immediately followed by a closing ']'. FormCalc uses '[*]' to denote AstEveryOccurence (all occurrences of a SOM node); any token other than ']' after the '*' is rejected. The error message comes from Errors.index.","triggerScenarios":"A FormCalc index expression like 'foo[* +' or 'foo[* x]' — i.e., the lexer emitted TOKEN.times for the '*' but the next token is not TOKEN.rightBracket. Reached when PDF.js evaluates an XFA form's script (calc/event/initialize) containing such a wildcard reference.","commonSituations":"Loading an XFA-enabled PDF whose embedded FormCalc script has a typo in a wildcard subscript; a hand-edited or generator-emitted XFA packet with malformed '*'; a corrupted/truncated form script where bytes were dropped inside '[*]'.","solutions":["Inspect the offending FormCalc script in the XFA packet (the SOM reference with '[*') and ensure every '[*]' is written exactly as bracket-star-bracket.","Regenerate or repair the XFA form source (XDP/PDF) with a conformant FormCalc authoring tool rather than hand-editing the script bytes.","If you do not control the PDF, catch the parser error at the XFA-binding layer and skip the malformed script so the rest of the document still renders.","Verify the FormCalc token stream with a standalone FormCalc lexer to confirm the '*' is immediately followed by ']' in the source text."],"exampleFix":"// before (FormCalc source inside XFA)\nvar x = Subform[* +1];\n// after\nvar x = Subform[*];","handlingStrategy":"validation","validationCode":"// Validate a FormCalc wildcard index before binding the XFA script.\n// Rejects '[*]' patterns not written as exactly [*].\nfunction hasMalformedWildcard(script) {\n  // matches '[*' not immediately followed by ']'\n  return /\\[\\*(?!\\])/.test(script);\n}\nif (hasMalformedWildcard(formCalcSrc)) {\n  // skip binding this script; log the offset\n}","typeGuard":null,"tryCatchPattern":"// Wrap XFA script evaluation; FormCalc parse errors are plain Error.\ntry {\n  bindFormCalcScript(xfaNode, src);\n} catch (e) {\n  if (e instanceof Error && /Invalid token in index\\./.test(e.message)) {\n    console.warn(\"Skipping malformed FormCalc index script\", e.message);\n    return;\n  }\n  throw e;\n}","preventionTips":["Author FormCalc wildcard subscripts only as '[*]' in a FormCalc-aware tool.","Lint SOM reference expressions before binding them to XFA nodes.","Never hand-edit the raw script bytes of an XFA packet."],"tags":["xfa","formcalc","parser","syntax"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}