diff --git a/src/cases.spec.ts b/src/cases.spec.ts index 18d9159..91ff6a5 100644 --- a/src/cases.spec.ts +++ b/src/cases.spec.ts @@ -136,6 +136,16 @@ export const PARSER_TESTS: ParserTestSet[] = [ '/:"test"stuff', ), }, + { + path: "\\\\:test", + expected: new TokenData( + [ + { type: "text", value: "\\" }, + { type: "param", name: "test" }, + ], + "\\\\:test", + ), + }, ]; export const STRINGIFY_TESTS: StringifyTestSet[] = [ @@ -204,6 +214,13 @@ export const STRINGIFY_TESTS: StringifyTestSet[] = [ ]), expected: '/:"test"stuff', }, + { + data: new TokenData([ + { type: "text", value: "\\" }, + { type: "param", name: "test" }, + ]), + expected: "\\\\:test", + }, ]; export const COMPILE_TESTS: CompileTestSet[] = [ diff --git a/src/index.ts b/src/index.ts index 9835698..36f1635 100644 --- a/src/index.ts +++ b/src/index.ts @@ -102,7 +102,7 @@ const SIMPLE_TOKENS: Record = { * Escape text for stringify to path. */ function escapeText(str: string) { - return str.replace(/[{}()\[\]+?!:*]/g, "\\$&"); + return str.replace(/[{}()\[\]+?!:*\\]/g, "\\$&"); } /**