Skip to content

Commit d297c33

Browse files
authored
Escapes markdown descriptions (#548)
This avoids accidental closing of comment tags. Fixes #547
1 parent bf2b791 commit d297c33

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { OpenAPI2, OpenAPI3, ReferenceObject } from "./types";
22

33
export function comment(text: string): string {
4-
const commentText = text.trim();
4+
const commentText = text.trim().replace(/\*\//g, "*\\/");
55

66
// if single-line comment
77
if (commentText.indexOf("\n") === -1) {

tests/utils/index.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { swaggerVersion } from "../../src/utils";
1+
import { swaggerVersion, comment } from "../../src/utils";
22

33
describe("swaggerVersion", () => {
44
it("v2", () => {
@@ -11,3 +11,18 @@ describe("swaggerVersion", () => {
1111
expect(() => swaggerVersion({} as any)).toThrow();
1212
});
1313
});
14+
15+
describe("comment", () => {
16+
it("escapes markdown in comments", () => {
17+
const text = `Example markdown
18+
**/some/url/path**`;
19+
20+
expect(comment(text)).toBe(
21+
`/**
22+
* Example markdown
23+
* **\\/some/url/path**
24+
*/
25+
`
26+
);
27+
});
28+
});

0 commit comments

Comments
 (0)