Skip to content

Commit 1b4791e

Browse files
committed
Escape text should escape backslash
1 parent a6bdf40 commit 1b4791e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/cases.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ export const PARSER_TESTS: ParserTestSet[] = [
136136
'/:"test"stuff',
137137
),
138138
},
139+
{
140+
path: "\\\\:test",
141+
expected: new TokenData(
142+
[
143+
{ type: "text", value: "\\" },
144+
{ type: "param", name: "test" },
145+
],
146+
"\\\\:test",
147+
),
148+
},
139149
];
140150

141151
export const STRINGIFY_TESTS: StringifyTestSet[] = [
@@ -204,6 +214,13 @@ export const STRINGIFY_TESTS: StringifyTestSet[] = [
204214
]),
205215
expected: '/:"test"stuff',
206216
},
217+
{
218+
data: new TokenData([
219+
{ type: "text", value: "\\" },
220+
{ type: "param", name: "test" },
221+
]),
222+
expected: "\\\\:test",
223+
},
207224
];
208225

209226
export const COMPILE_TESTS: CompileTestSet[] = [

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const SIMPLE_TOKENS: Record<string, TokenType> = {
102102
* Escape text for stringify to path.
103103
*/
104104
function escapeText(str: string) {
105-
return str.replace(/[{}()\[\]+?!:*]/g, "\\$&");
105+
return str.replace(/[{}()\[\]+?!:*\\]/g, "\\$&");
106106
}
107107

108108
/**

0 commit comments

Comments
 (0)