Skip to content

Commit a7662fa

Browse files
Don't attempt to double-escape double quotes (#1076)
1 parent c2c186e commit a7662fa

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface CommentObject {
2525

2626
const COMMENT_RE = /\*\//g;
2727
export const LB_RE = /\r?\n/g;
28-
export const DOUBLE_QUOTE_RE = /"/g;
28+
export const DOUBLE_QUOTE_RE = /(?<!\\)"/g;
2929
const ESC_0_RE = /~0/g;
3030
const ESC_1_RE = /~1/g;
3131
const TILDE_RE = /~/g;

test/utils.test.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { tsIntersectionOf, tsUnionOf } from "../src/utils.js";
1+
import { parseRef, tsIntersectionOf, tsUnionOf } from "../src/utils.js";
22

33
describe("utils", () => {
44
describe("tsUnionOf", () => {
@@ -61,4 +61,22 @@ describe("utils", () => {
6161
});
6262
});
6363
});
64-
});
64+
65+
describe("parseRef", () => {
66+
it("basic", () => {
67+
expect(parseRef("#/test/schema-object")).toStrictEqual({ filename: ".", path: [ "test", "schema-object" ] });
68+
});
69+
70+
it("double quote", () => {
71+
expect(parseRef("#/test/\"")).toStrictEqual({ filename: ".", path: [ "test", '\\\"' ] });
72+
});
73+
74+
it("escaped double quote", () => {
75+
expect(parseRef("#/test/\\\"")).toStrictEqual({ filename: ".", path: [ "test", '\\\"' ] });
76+
});
77+
78+
it("tilde escapes", () => {
79+
expect(parseRef("#/test/~1~0")).toStrictEqual({ filename: ".", path: [ "test", "/~" ] });
80+
});
81+
});
82+
});

0 commit comments

Comments
 (0)