File tree Expand file tree Collapse file tree 4 files changed +12
-4
lines changed Expand file tree Collapse file tree 4 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,12 @@ import { escapeDescription } from './escapeDescription';
2
2
3
3
describe ( 'escapeDescription' , ( ) => {
4
4
it ( 'should escape' , ( ) => {
5
+ expect ( escapeDescription ( 'foo `test` bar' ) ) . toEqual ( 'foo \\`test\\` bar' ) ;
6
+ } ) ;
7
+
8
+ it ( 'should not escape' , ( ) => {
5
9
expect ( escapeDescription ( '' ) ) . toEqual ( '' ) ;
6
10
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' ) ;
8
12
} ) ;
9
13
} ) ;
Original file line number Diff line number Diff line change 1
1
export function escapeDescription ( value : string ) : string {
2
- return value . replace ( / ` / g, '\\`' ) ;
2
+ return value . replace ( / ( [ ^ \\ ] ) ` / g, '$1 \\`' ) ;
3
3
}
Original file line number Diff line number Diff line change @@ -2,8 +2,12 @@ import { escapeDescription } from './escapeDescription';
2
2
3
3
describe ( 'escapeDescription' , ( ) => {
4
4
it ( 'should escape' , ( ) => {
5
+ expect ( escapeDescription ( 'foo `test` bar' ) ) . toEqual ( 'foo \\`test\\` bar' ) ;
6
+ } ) ;
7
+
8
+ it ( 'should not escape' , ( ) => {
5
9
expect ( escapeDescription ( '' ) ) . toEqual ( '' ) ;
6
10
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' ) ;
8
12
} ) ;
9
13
} ) ;
Original file line number Diff line number Diff line change 1
1
export function escapeDescription ( value : string ) : string {
2
- return value . replace ( / ` / g, '\\`' ) ;
2
+ return value . replace ( / ( [ ^ \\ ] ) ` / g, '$1 \\`' ) ;
3
3
}
You can’t perform that action at this time.
0 commit comments