Skip to content

Commit 2fcd655

Browse files
Backquote/backtick symbol (`) is not escaped correctly
1 parent df9e447 commit 2fcd655

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/openApi/v2/parser/escapeDescription.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import { escapeDescription } from './escapeDescription';
22

33
describe('escapeDescription', () => {
44
it('should escape', () => {
5+
expect(escapeDescription('foo `test` bar')).toEqual('foo \\`test\\` bar');
6+
});
7+
8+
it('should not escape', () => {
59
expect(escapeDescription('')).toEqual('');
610
expect(escapeDescription('fooBar')).toEqual('fooBar');
7-
expect(escapeDescription('foo `test` bar')).toEqual('foo \\`test\\` bar');
11+
expect(escapeDescription('foo \\`test\\` bar')).toEqual('foo \\`test\\` bar');
812
});
913
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export function escapeDescription(value: string): string {
2-
return value.replace(/`/g, '\\`');
2+
return value.replace(/([^\\])`/g, '$1\\`');
33
}

src/openApi/v3/parser/escapeDescription.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import { escapeDescription } from './escapeDescription';
22

33
describe('escapeDescription', () => {
44
it('should escape', () => {
5+
expect(escapeDescription('foo `test` bar')).toEqual('foo \\`test\\` bar');
6+
});
7+
8+
it('should not escape', () => {
59
expect(escapeDescription('')).toEqual('');
610
expect(escapeDescription('fooBar')).toEqual('fooBar');
7-
expect(escapeDescription('foo `test` bar')).toEqual('foo \\`test\\` bar');
11+
expect(escapeDescription('foo \\`test\\` bar')).toEqual('foo \\`test\\` bar');
812
});
913
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export function escapeDescription(value: string): string {
2-
return value.replace(/`/g, '\\`');
2+
return value.replace(/([^\\])`/g, '$1\\`');
33
}

0 commit comments

Comments
 (0)