This commit is contained in:
Ferdi Koomen 2021-03-12 21:19:56 +01:00
parent fb7caaeb78
commit 13bf29c198
8 changed files with 8 additions and 4 deletions

View File

@ -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/*');
});
});

View File

@ -1,3 +1,3 @@
export function escapeDescription(value: string): string {
return value.replace(/([^\\])`/g, '$1\\`');
return value.replace(/([^\\])`/g, '$1\\`').replace(/(\*\/)/g, '*_/');
}

View File

@ -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);
});

View File

@ -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;
}

View File

@ -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/*');
});
});

View File

@ -1,3 +1,3 @@
export function escapeDescription(value: string): string {
return value.replace(/([^\\])`/g, '$1\\`');
return value.replace(/([^\\])`/g, '$1\\`').replace(/(\*\/)/g, '*_/');
}

View File

@ -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);
});

View File

@ -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;
}