File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -2,12 +2,15 @@ import assertString from './util/assertString';
2
2
3
3
export default function unescape ( str ) {
4
4
assertString ( str ) ;
5
- return ( str . replace ( / & a m p ; / g, '&' )
6
- . replace ( / & q u o t ; / g, '"' )
5
+ return ( str . replace ( / & q u o t ; / g, '"' )
7
6
. replace ( / & # x 2 7 ; / g, "'" )
8
7
. replace ( / & l t ; / g, '<' )
9
8
. replace ( / & g t ; / g, '>' )
10
9
. replace ( / & # x 2 F ; / g, '/' )
11
10
. replace ( / & # x 5 C ; / g, '\\' )
12
- . replace ( / & # 9 6 ; / g, '`' ) ) ;
11
+ . replace ( / & # 9 6 ; / g, '`' )
12
+ . replace ( / & a m p ; / g, '&' ) ) ;
13
+ // & replacement has to be the last one to prevent
14
+ // bugs with intermediate strings containing escape sequences
15
+ // See: https://github.com/validatorjs/validator.js/issues/1827
13
16
}
Original file line number Diff line number Diff line change @@ -184,6 +184,9 @@ describe('Sanitizers', () => {
184
184
185
185
'Backtick: `' :
186
186
'Backtick: `' ,
187
+
188
+ 'Escaped string: &lt;' :
189
+ 'Escaped string: <' ,
187
190
} ,
188
191
} ) ;
189
192
} ) ;
You can’t perform that action at this time.
0 commit comments