{"record":{"id":"92394baf55ae022b","repo":"karatelabs/karate","slug":"invalid-escape-sequence-in-template-literal-0-digit","errorCode":null,"errorMessage":"invalid escape sequence in template literal: \\0<digit>","messagePattern":"invalid escape sequence in template literal: \\\\0<digit>","errorType":"exception","errorClass":"io.karatelabs.parser.ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsLexer.java","lineNumber":394,"sourceCode":"            }\n            if (c == '$' && peek(1) == '{') {\n                break;\n            }\n            if (c == '\\\\') {\n                advance();\n                if (isAtEnd()) {\n                    break;\n                }\n                char esc = peek();\n                // Spec: in non-tagged template literals, malformed escape sequences are\n                // early errors. We have no way to tell tag vs no-tag at lex time, so we\n                // reject at lex time; tagged templates are not yet supported anyway.\n                // Invalid legacy octal: \\1..\\9 or \\0 followed by a decimal digit.\n                if (esc >= '1' && esc <= '9') {\n                    throw new ParserException(\"invalid escape sequence in template literal: \\\\\" + esc);\n                }\n                if (esc == '0' && peek(1) >= '0' && peek(1) <= '9') {\n                    throw new ParserException(\"invalid escape sequence in template literal: \\\\0\" + peek(1));\n                }\n                // Hex escape backslash-x HH — require exactly two hex digits.\n                if (esc == 'x') {\n                    if (!isHexDigit(peek(1)) || !isHexDigit(peek(2))) {\n                        throw new ParserException(\"invalid hex escape sequence in template literal\");\n                    }\n                }\n                // Unicode escape backslash-u HHHH or backslash-u {H...} — require proper form.\n                if (esc == 'u') {\n                    char next = peek(1);\n                    if (next == '{') {\n                        // backslash-u { codepoint } — one or more hex digits, closed by }\n                        int j = 2;\n                        if (!isHexDigit(peek(j))) {\n                            throw new ParserException(\"invalid unicode escape sequence in template literal\");\n                        }\n                        int codepoint = 0;\n                        while (isHexDigit(peek(j))) {","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsLexer.java#L376-L412","documentation":"\\0 followed by another decimal digit is an invalid legacy octal escape in template literals (ES spec early error), so the lexer rejects it. \\0 alone (NUL) is fine, but \\01, \\05 etc. are not. Escape the digit separately or drop the extra digit.","triggerScenarios":"A template literal contains \\0 immediately followed by a digit, e.g. `\\05` or an interpolated/built string like `prefix\\0${i}` where the digit follows; detected at JsLexer.java:394 in scanTemplateContent.","commonSituations":"Building NUL-delimited strings with appended counters, porting C/old-JS octal escapes, generated payloads where \\0 ends up adjacent to a digit, naive binary-data templates.","solutions":["Use just \\0 and put the digit elsewhere (e.g. `\\0` + String(i))","Escape the backslash: `\\\\0${i}` if you want a literal backslash-zero then digit","Use the explicit hex/codepoint escape \\x00 or \\u0000 instead of bare \\0","Reorder the string so a digit never directly follows the NUL escape"],"exampleFix":"// before\nvar rec = `row\\05`;\n// after\nvar rec = `row\\u0000` + '5'; // or `row\\x005` via concatenation","handlingStrategy":"validation","validationCode":"if (/\\\\0[0-9]/.test(tpl)) throw new Error('\\\\0 followed by a digit is an invalid octal escape');","typeGuard":"null","tryCatchPattern":"try {\n  karate.eval('var s = `' + tpl + '`;');\n} catch (e) {\n  if (String(e.message).indexOf('\\\\0') >= 0) {\n    tpl = tpl.replace(/\\\\0(?=[0-9])/g, '\\\\u0000');\n  } else throw e;\n}","preventionTips":["Use \\u0000 (or concatenation) instead of bare \\0 when digits follow","Escape backslashes in dynamically built strings","Keep NUL-delimited data out of template literals; use arrays and join","Lint generated strings for backslash-digit sequences"],"tags":["javascript","lexer","template-literal","escape-sequence"],"backgroundTag":"invalid-escape-sequence","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"}