File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,9 @@ module.exports = function serialize(obj, options) {
8383 // Replace unsafe HTML and invalid JavaScript line terminator chars with
8484 // their safe Unicode char counterpart. This _must_ happen before the
8585 // regexps and functions are serialized and added back to the string.
86- str = str . replace ( UNSAFE_CHARS_REGEXP , escapeUnsafeChars ) ;
86+ if ( ! options . disableEscapeUnsafe ) {
87+ str = str . replace ( UNSAFE_CHARS_REGEXP , escapeUnsafeChars ) ;
88+ }
8789
8890 if ( functions . length === 0 && regexps . length === 0 ) {
8991 return str ;
Original file line number Diff line number Diff line change @@ -198,6 +198,11 @@ describe('serialize( obj )', function () {
198198
199199 expect ( serialize ( fn , { isJSON : true } ) ) . to . equal ( 'undefined' ) ;
200200 } ) ;
201+
202+ it ( 'should accept a `disableEscapeUnsafe` option' , function ( ) {
203+ expect ( serialize ( '<' , { disableEscapeUnsafe : false } ) ) . to . equal ( '"\\u003C"' ) ;
204+ expect ( serialize ( '<' , { disableEscapeUnsafe : true } ) ) . to . equal ( '\"<\"' ) ;
205+ } ) ;
201206 } ) ;
202207
203208 describe ( 'backwards-compatability' , function ( ) {
You can’t perform that action at this time.
0 commit comments