Skip to content

Commit f582891

Browse files
authored
Merge pull request ferdikoomen#452 from raman-savitski/master
Backquote/backtick symbol (`) is not escaped correctly
2 parents 574bd2f + 2fcd655 commit f582891

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { escapeDescription } from './escapeDescription';
2+
3+
describe('escapeDescription', () => {
4+
it('should escape', () => {
5+
expect(escapeDescription('foo `test` bar')).toEqual('foo \\`test\\` bar');
6+
});
7+
8+
it('should not escape', () => {
9+
expect(escapeDescription('')).toEqual('');
10+
expect(escapeDescription('fooBar')).toEqual('fooBar');
11+
expect(escapeDescription('foo \\`test\\` bar')).toEqual('foo \\`test\\` bar');
12+
});
13+
});
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, '$1\\`');
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { escapeDescription } from './escapeDescription';
2+
3+
describe('escapeDescription', () => {
4+
it('should escape', () => {
5+
expect(escapeDescription('foo `test` bar')).toEqual('foo \\`test\\` bar');
6+
});
7+
8+
it('should not escape', () => {
9+
expect(escapeDescription('')).toEqual('');
10+
expect(escapeDescription('fooBar')).toEqual('fooBar');
11+
expect(escapeDescription('foo \\`test\\` bar')).toEqual('foo \\`test\\` bar');
12+
});
13+
});
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, '$1\\`');
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)