From 13bf29c1986dab60171cc54535925baba836a50c Mon Sep 17 00:00:00 2001 From: Ferdi Koomen Date: Fri, 12 Mar 2021 21:19:56 +0100 Subject: [PATCH] Fixed #596 --- src/openApi/v2/parser/escapeDescription.spec.ts | 1 + src/openApi/v2/parser/escapeDescription.ts | 2 +- src/openApi/v2/parser/getComment.spec.ts | 1 + src/openApi/v2/parser/getComment.ts | 2 +- src/openApi/v3/parser/escapeDescription.spec.ts | 1 + src/openApi/v3/parser/escapeDescription.ts | 2 +- src/openApi/v3/parser/getComment.spec.ts | 1 + src/openApi/v3/parser/getComment.ts | 2 +- 8 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/openApi/v2/parser/escapeDescription.spec.ts b/src/openApi/v2/parser/escapeDescription.spec.ts index d4aae6d7..5823eec0 100644 --- a/src/openApi/v2/parser/escapeDescription.spec.ts +++ b/src/openApi/v2/parser/escapeDescription.spec.ts @@ -9,5 +9,6 @@ describe('escapeDescription', () => { expect(escapeDescription('')).toEqual(''); expect(escapeDescription('fooBar')).toEqual('fooBar'); expect(escapeDescription('foo \\`test\\` bar')).toEqual('foo \\`test\\` bar'); + expect(escapeDescription('foo */bar/*')).toEqual('foo *_/bar/*'); }); }); diff --git a/src/openApi/v2/parser/escapeDescription.ts b/src/openApi/v2/parser/escapeDescription.ts index 087abf8a..fc0b05a1 100644 --- a/src/openApi/v2/parser/escapeDescription.ts +++ b/src/openApi/v2/parser/escapeDescription.ts @@ -1,3 +1,3 @@ export function escapeDescription(value: string): string { - return value.replace(/([^\\])`/g, '$1\\`'); + return value.replace(/([^\\])`/g, '$1\\`').replace(/(\*\/)/g, '*_/'); } diff --git a/src/openApi/v2/parser/getComment.spec.ts b/src/openApi/v2/parser/getComment.spec.ts index 1288212d..208a7d23 100644 --- a/src/openApi/v2/parser/getComment.spec.ts +++ b/src/openApi/v2/parser/getComment.spec.ts @@ -8,6 +8,7 @@ describe('getComment', () => { expect(getComment('')).toEqual(null); expect(getComment('Hello')).toEqual('Hello'); expect(getComment('Hello World!')).toEqual('Hello World!'); + expect(getComment('Testing */escape/*')).toEqual('Testing *_/escape/*'); expect(getComment('Testing multiline comments.\nThis must go to the next line.\n\nThis will contain a break.')).toEqual(multiline); expect(getComment('Testing multiline comments.\r\nThis must go to the next line.\r\n\r\nThis will contain a break.')).toEqual(multiline); }); diff --git a/src/openApi/v2/parser/getComment.ts b/src/openApi/v2/parser/getComment.ts index 7c162cfd..cf126b9c 100644 --- a/src/openApi/v2/parser/getComment.ts +++ b/src/openApi/v2/parser/getComment.ts @@ -7,7 +7,7 @@ import { EOL } from 'os'; */ export function getComment(comment?: string): string | null { if (comment) { - return comment.replace(/\r?\n(.*)/g, (_, w) => `${EOL} * ${w.trim()}`); + return comment.replace(/(\*\/)/g, '*_/').replace(/\r?\n(.*)/g, (_, w) => `${EOL} * ${w.trim()}`); } return null; } diff --git a/src/openApi/v3/parser/escapeDescription.spec.ts b/src/openApi/v3/parser/escapeDescription.spec.ts index d4aae6d7..5823eec0 100644 --- a/src/openApi/v3/parser/escapeDescription.spec.ts +++ b/src/openApi/v3/parser/escapeDescription.spec.ts @@ -9,5 +9,6 @@ describe('escapeDescription', () => { expect(escapeDescription('')).toEqual(''); expect(escapeDescription('fooBar')).toEqual('fooBar'); expect(escapeDescription('foo \\`test\\` bar')).toEqual('foo \\`test\\` bar'); + expect(escapeDescription('foo */bar/*')).toEqual('foo *_/bar/*'); }); }); diff --git a/src/openApi/v3/parser/escapeDescription.ts b/src/openApi/v3/parser/escapeDescription.ts index 087abf8a..fc0b05a1 100644 --- a/src/openApi/v3/parser/escapeDescription.ts +++ b/src/openApi/v3/parser/escapeDescription.ts @@ -1,3 +1,3 @@ export function escapeDescription(value: string): string { - return value.replace(/([^\\])`/g, '$1\\`'); + return value.replace(/([^\\])`/g, '$1\\`').replace(/(\*\/)/g, '*_/'); } diff --git a/src/openApi/v3/parser/getComment.spec.ts b/src/openApi/v3/parser/getComment.spec.ts index 1288212d..208a7d23 100644 --- a/src/openApi/v3/parser/getComment.spec.ts +++ b/src/openApi/v3/parser/getComment.spec.ts @@ -8,6 +8,7 @@ describe('getComment', () => { expect(getComment('')).toEqual(null); expect(getComment('Hello')).toEqual('Hello'); expect(getComment('Hello World!')).toEqual('Hello World!'); + expect(getComment('Testing */escape/*')).toEqual('Testing *_/escape/*'); expect(getComment('Testing multiline comments.\nThis must go to the next line.\n\nThis will contain a break.')).toEqual(multiline); expect(getComment('Testing multiline comments.\r\nThis must go to the next line.\r\n\r\nThis will contain a break.')).toEqual(multiline); }); diff --git a/src/openApi/v3/parser/getComment.ts b/src/openApi/v3/parser/getComment.ts index 7c162cfd..cf126b9c 100644 --- a/src/openApi/v3/parser/getComment.ts +++ b/src/openApi/v3/parser/getComment.ts @@ -7,7 +7,7 @@ import { EOL } from 'os'; */ export function getComment(comment?: string): string | null { if (comment) { - return comment.replace(/\r?\n(.*)/g, (_, w) => `${EOL} * ${w.trim()}`); + return comment.replace(/(\*\/)/g, '*_/').replace(/\r?\n(.*)/g, (_, w) => `${EOL} * ${w.trim()}`); } return null; }