{"record":{"id":"1e9e0c527047aaac","repo":"mozilla/pdf.js","slug":"invalid-psf-in-afspecial-format","errorCode":null,"errorMessage":"Invalid psf in AFSpecial_Format","messagePattern":"Invalid psf in AFSpecial_Format","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/scripting_api/aform.js","lineNumber":429,"sourceCode":"    let formatStr;\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 =\n          this._util.printx(\"9999999999\", event.value).length >= 10\n            ? \"(999) 999-9999\"\n            : \"999-9999\";\n        break;\n      case 3:\n        formatStr = \"999-99-9999\";\n        break;\n      default:\n        throw new Error(\"Invalid psf in AFSpecial_Format\");\n    }\n\n    event.value = this._util.printx(formatStr, event.value);\n  }\n\n  AFSpecial_KeystrokeEx(cMask) {\n    const event = globalThis.event;\n\n    // Simplify the format string by removing all characters that are not\n    // specific to the format because the user could enter 1234567 when the\n    // format is 999-9999.\n    const simplifiedFormatStr = cMask.replaceAll(/[^9AOX]/g, \"\");\n    this.#AFSpecial_KeystrokeEx_helper(simplifiedFormatStr, null, false);\n    if (event.rc) {\n      return;\n    }\n\n    event.rc = true;","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/aform.js#L411-L447","documentation":"Thrown by AFSpecial_Format when the psf (special-format) selector is not 0 (zip), 1 (zip+4), 2 (phone), or 3 (SSN). The function builds a mask string per known format and rejects anything else via the default branch. It runs inside the sandboxed PDF-JS form environment invoked by the PDF.","triggerScenarios":"A PDF form script calls AFSpecial_Format(psf) with psf outside [0,3].","commonSituations":"A malformed format specifier in the PDF; an authoring tool emitting a non-standard psf; a calculated psf that falls outside the valid range.","solutions":["Repair or report the PDF form script; the error is content-driven.","Update PDF.js for any improved tolerance.","Ensure the embedding app degrades gracefully when formatting throws.","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_Format/.test(e.message)) { /* skip formatting */ }\n}","preventionTips":["Treat AFSpecial_Format errors as non-fatal, content-driven issues.","Repair PDFs that pass out-of-range psf selectors.","Update PDF.js for any improved tolerance.","Keep forms functional when formatting fails."],"tags":["aform","scripting","format","pdf-content"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}