{"record":{"id":"1507873c50d85614","repo":"karatelabs/karate","slug":"octal-literals-are-not-allowed-in-strict-mode","errorCode":null,"errorMessage":"octal literals are not allowed in strict mode","messagePattern":"octal literals are not allowed in strict mode","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":1495,"sourceCode":"\n    /** Strict-mode early error for a legacy octal ({@code 0755}) or NonOctalDecimal\n     *  ({@code 08} / {@code 09}) integer literal — any NUMBER whose text starts with\n     *  {@code 0} immediately followed by a decimal digit. {@code 0x…} / {@code 0b…} /\n     *  {@code 0o…} / {@code 0.…} / {@code 0e…} have a non-digit second char and a plain\n     *  {@code 0} is length 1, so all are correctly excluded. */\n    private static void checkLegacyOctalLiteral(Node litExpr) {\n        if (litExpr.size() != 1) {\n            return;\n        }\n        Node tok = litExpr.getFirst();\n        if (!tok.isToken() || tok.token.type != NUMBER) {\n            return;\n        }\n        String text = tok.getText();\n        if (text.length() >= 2 && text.charAt(0) == '0') {\n            char c = text.charAt(1);\n            if (c >= '0' && c <= '9') {\n                throw new ParserException(\"octal literals are not allowed in strict mode\");\n            }\n        }\n    }\n\n    // CoverInitializedName early error (§12.2.6.1): a shorthand-with-default\n    // (`IDENT = AssignmentExpression`) inside object-literal braces is only legal\n    // when the surrounding `{...}` is refined as an ObjectAssignmentPattern /\n    // ObjectBindingPattern; in a plain object literal it is a SyntaxError. The\n    // parser accepts the cover form unconditionally in `object_elem()` (at parse\n    // time it can't yet tell whether `{...}` is an assignment LHS / binding / arrow\n    // param), so `earlyErrors` rejects it where pattern context never materializes.\n    // That check and the pattern-context rest-element rules below are applied inline\n    // by `earlyErrors`, which threads `inPattern` via `childInPatternContext`.\n\n    /**\n     * Spec early errors for {@code BindingRestElement} / {@code AssignmentRestElement}\n     * inside an {@code ArrayBindingPattern} / {@code ArrayAssignmentPattern}:\n     * <ul>","sourceCodeStart":1477,"sourceCodeEnd":1513,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L1477-L1513","documentation":"Strict-mode early error: the parser found an integer literal written with a legacy octal prefix, e.g. `0755` (or NonOctalDecimal like `08`/`09`). Legacy octal literals are forbidden in strict mode; use the `0o` prefix instead. Thrown at parse time, before execution.","triggerScenarios":"Parsing any NUMBER token whose text starts with '0' followed by a digit 0-9, e.g. `var mode = 0755;` or `08` inside strict-mode code — the literal-length and char checks in the octal validator fire.","commonSituations":"Copying file-permission constants (`0755`, `0644`) from shell/POSIX examples into Karate JS; older scripts written before ES5 strict mode; dates like `08` typed with a leading zero.","solutions":["Rewrite the literal with the modern octal prefix: `0755` becomes `0o755`","Use a decimal literal instead if octal was not intended (`755`)","Strip the leading zero for values like `08` -> `8`","Compute the value explicitly if you need the octal interpretation: `parseInt('755', 8)`"],"exampleFix":"// before\nvar perms = 0755; // legacy octal\n// after\nvar perms = 0o755;","handlingStrategy":"validation","validationCode":"// flag legacy octal / leading-zero literals before parsing\nconst legacyOctal = /\\b0[0-9]+\\b/;\nif (legacyOctal.test(src)) {\n  throw new Error('script contains legacy octal literal (use 0o prefix)');\n}","typeGuard":null,"tryCatchPattern":"try {\n  parseScript(src);\n} catch (e) {\n  if (String(e).includes('octal literals are not allowed')) {\n    // rewrite literal with 0o prefix or decimal\n  }\n  throw e;\n}","preventionTips":["Always use the 0o prefix for octal constants","Never write leading zeros on decimal literals","Run ESLint (no-octal-legacy) on embedded JS"],"tags":["javascript","parser","strict-mode","octal-literal"],"backgroundTag":"invalid-literal-syntax","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}