{"record":{"id":"0dba3456bf43b3ad","repo":"toon-format/toon","slug":"invalid-escape-sequence-next","errorCode":null,"errorMessage":"Invalid escape sequence: \\${next}","messagePattern":"Invalid escape sequence: \\\\(.+?)","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"packages/toon/src/shared/string-utils.ts","lineNumber":101,"sourceCode":"      }\n      if (next === 'u') {\n        if (i + 6 > value.length) {\n          throw new SyntaxError(`Invalid escape sequence: truncated \\\\u escape at \"${value.slice(i, i + 6)}\"`)\n        }\n        const hex = value.slice(i + 2, i + 6)\n        if (!/^[0-9a-f]{4}$/i.test(hex)) {\n          throw new SyntaxError(`Invalid escape sequence: \\\\u must be followed by 4 hex digits, got \"${hex}\"`)\n        }\n        const codeUnit = Number.parseInt(hex, 16)\n        if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) {\n          throw new SyntaxError(`Invalid escape sequence: \\\\u${hex} is a lone surrogate. Supplementary code points MUST appear as literal UTF-8`)\n        }\n        unescaped += String.fromCodePoint(codeUnit)\n        i += 6\n        continue\n      }\n\n      throw new SyntaxError(`Invalid escape sequence: \\\\${next}`)\n    }\n\n    unescaped += value[i]\n    i++\n  }\n\n  return unescaped\n}\n\n/** Finds the index of the closing double quote, accounting for escape sequences. */\nexport function findClosingQuote(content: string, start: number): number {\n  let i = start + 1\n  while (i < content.length) {\n    if (content[i] === BACKSLASH && i + 1 < content.length) {\n      i += 2\n      continue\n    }\n    if (content[i] === DOUBLE_QUOTE) {","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/toon-format/toon/blob/604eac266e35166bed6f5b9e3bd586e9c60a9330/packages/toon/src/shared/string-utils.ts#L83-L119","documentation":"unescapeString only permits the escapes \\n, \\t, \\\", \\\\ and \\uXXXX. Any other character following a backslash is an unknown escape and throws this SyntaxError naming the offending character.","triggerScenarios":"Parsing a quoted TOON string with escapes like \\x41, \\0, \\' or a raw \\ followed by any character other than n, t, \", \\ or u.","commonSituations":"Authors copying escape conventions from JavaScript/regex strings (\\x, \\0, \\/) into TOON files; single-quoted strings converted to double-quoted TOON strings leaving \\' escapes behind.","solutions":["Replace the unsupported escape with the literal character (e.g. \\' → ')","Use only the supported escapes: \\n \\t \\\" \\\\ and \\uXXXX","Re-encode the string with the library's encoder to produce valid escaping"],"exampleFix":"// before (TOON input)\ngreeting: \"It\\'s fine\"\n// after\ngreeting: \"It's fine\"","handlingStrategy":"validation","validationCode":"function hasOnlySupportedEscapes(s: string): boolean {\n  return !/\\\\(?![nt\"\\\\u])/.test(s.replace(/\\\\u[0-9a-fA-F]{4}/g, ''))\n}","typeGuard":null,"tryCatchPattern":"try {\n  const value = decode(input)\n} catch (e) {\n  if (e instanceof SyntaxError && e.message.startsWith('Invalid escape sequence: \\\\')) {\n    // strip/replace the unsupported escape reported in the message\n  }\n  throw e\n}","preventionTips":["Memorize the supported escape set: \\n \\t \\\" \\\\ \\uXXXX","Do not copy JS/regex escape conventions into TOON strings","Prefer the encoder over hand-written escaping"],"tags":["decoder","escape-sequence","syntax-error","string-parsing"],"backgroundTag":"invalid-escape-sequence","analyzedSha":"604eac266e35166bed6f5b9e3bd586e9c60a9330","analyzedAt":"2026-08-31T11:09:25.043Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}