Skip to content

Commit 81bc560

Browse files
authored
Merge pull request #1 from redmedical/feature/optionReplace
feat(serialize): implement option to disable escaping of unsafe chara…
2 parents adfee60 + 0066142 commit 81bc560

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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;

test/unit/serialize.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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 () {

0 commit comments

Comments
 (0)