{"record":{"id":"68c27044a9453129","repo":"mozilla/pdf.js","slug":"invalid-psf-in-afspecial-keystroke","errorCode":null,"errorMessage":"Invalid psf in AFSpecial_Keystroke","messagePattern":"Invalid psf in AFSpecial_Keystroke","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/scripting_api/aform.js","lineNumber":557,"sourceCode":"\n    let value = this.AFMergeChange(event);\n    let formatStr, secondFormatStr;\n    switch (psf) {\n      case 0:\n        formatStr = \"99999\";\n        break;\n      case 1:\n        formatStr = \"99999-9999\";\n        break;\n      case 2:\n        formatStr = \"999-9999\";\n        secondFormatStr = \"(999) 999-9999\";\n        break;\n      case 3:\n        formatStr = \"999-99-9999\";\n        break;\n      default:\n        throw new Error(\"Invalid psf in AFSpecial_Keystroke\");\n    }\n    const formats = secondFormatStr\n      ? [formatStr, secondFormatStr]\n      : [formatStr];\n    for (const format of formats) {\n      this.#AFSpecial_KeystrokeEx_helper(format, value, false);\n      if (event.rc) {\n        return;\n      }\n      event.rc = true;\n    }\n\n    const re = /[-()\\s]+/g;\n    value = value.replaceAll(re, \"\");\n    for (const format of formats) {\n      this.#AFSpecial_KeystrokeEx_helper(\n        format.replaceAll(re, \"\"),\n        value,","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/aform.js#L539-L575","documentation":"Thrown by AFSpecial_Keystroke when the psf selector is not 0 (zip), 1 (zip+4), 2 (phone), or 3 (SSN). Like AFSpecial_Format, it builds a mask per known format and rejects unknown selectors via the default branch. It executes within the sandboxed PDF-JS form layer.","triggerScenarios":"A PDF form script calls AFSpecial_Keystroke(psf) with psf outside [0,3].","commonSituations":"A malformed keystroke-format specifier in the PDF; an authoring tool emitting a non-standard psf.","solutions":["Repair or report the PDF form script; the error originates in PDF content.","Update PDF.js for any improved tolerance.","Tolerate scripting failures at the embedding level so input handling continues.","If authoring the PDF, use psf in 0..3."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await runFormScript(...);\n} catch (e) {\n  if (/Invalid psf in AFSpecial_Keystroke/.test(e.message)) { /* skip keystroke mask */ }\n}","preventionTips":["Treat keystroke-format errors as non-fatal content issues.","Repair PDFs that pass out-of-range psf selectors to keystroke handlers.","Update PDF.js for improved tolerance.","Keep input handling working when a mask cannot be applied."],"tags":["aform","scripting","keystroke","pdf-content"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}