Skip to content

Commit df9e447

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

File tree

6 files changed

+28
-2
lines changed

6 files changed

+28
-2
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { escapeDescription } from './escapeDescription';
2+
3+
describe('escapeDescription', () => {
4+
it('should escape', () => {
5+
expect(escapeDescription('')).toEqual('');
6+
expect(escapeDescription('fooBar')).toEqual('fooBar');
7+
expect(escapeDescription('foo `test` bar')).toEqual('foo \\`test\\` bar');
8+
});
9+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function escapeDescription(value: string): string {
2+
return value.replace(/`/g, '\\`');
3+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { OperationError } from '../../../client/interfaces/OperationError';
22
import type { OperationResponse } from '../../../client/interfaces/OperationResponse';
3+
import { escapeDescription } from './escapeDescription';
34

45
export function getOperationErrors(operationResponses: OperationResponse[]): OperationError[] {
56
return operationResponses
@@ -8,6 +9,6 @@ export function getOperationErrors(operationResponses: OperationResponse[]): Ope
89
})
910
.map(response => ({
1011
code: response.code,
11-
description: response.description!,
12+
description: escapeDescription(response.description!),
1213
}));
1314
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { escapeDescription } from './escapeDescription';
2+
3+
describe('escapeDescription', () => {
4+
it('should escape', () => {
5+
expect(escapeDescription('')).toEqual('');
6+
expect(escapeDescription('fooBar')).toEqual('fooBar');
7+
expect(escapeDescription('foo `test` bar')).toEqual('foo \\`test\\` bar');
8+
});
9+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function escapeDescription(value: string): string {
2+
return value.replace(/`/g, '\\`');
3+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { OperationError } from '../../../client/interfaces/OperationError';
22
import type { OperationResponse } from '../../../client/interfaces/OperationResponse';
3+
import { escapeDescription } from './escapeDescription';
34

45
export function getOperationErrors(operationResponses: OperationResponse[]): OperationError[] {
56
return operationResponses
@@ -8,6 +9,6 @@ export function getOperationErrors(operationResponses: OperationResponse[]): Ope
89
})
910
.map(response => ({
1011
code: response.code,
11-
description: response.description!,
12+
description: escapeDescription(response.description!),
1213
}));
1314
}

0 commit comments

Comments
 (0)