Skip to content

Commit

Permalink
Revert "support for bigint (yahoo#80)"
Browse files Browse the repository at this point in the history
This reverts commit 5130a71.
  • Loading branch information
okuryu committed May 28, 2020
1 parent 026a445 commit 7cee7e4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 29 deletions.
13 changes: 2 additions & 11 deletions index.js
Expand Up @@ -11,7 +11,7 @@ var randomBytes = require('randombytes');
// Generate an internal UID to make the regexp pattern harder to guess.
var UID_LENGTH = 16;
var UID = generateUID();
var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|U|I|B)-' + UID + '-(\\d+)__@"', 'g');
var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|U|I)-' + UID + '-(\\d+)__@"', 'g');

var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g;
var IS_PURE_FUNCTION = /function.*?\(/;
Expand Down Expand Up @@ -70,7 +70,6 @@ module.exports = function serialize(obj, options) {
var sets = [];
var undefs = [];
var infinities= [];
var bigInts = [];

// Returns placeholders for functions and regexps (identified by index)
// which are later replaced by their string representation.
Expand Down Expand Up @@ -120,10 +119,6 @@ module.exports = function serialize(obj, options) {
return '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
}

if (type === 'bigint') {
return '@__B-' + UID + '-' + (bigInts.push(origValue) - 1) + '__@';
}

return value;
}

Expand Down Expand Up @@ -197,7 +192,7 @@ module.exports = function serialize(obj, options) {
str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);
}

if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && undefs.length === 0 && infinities.length === 0 && bigInts.length === 0) {
if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && undefs.length === 0 && infinities.length === 0) {
return str;
}

Expand Down Expand Up @@ -236,10 +231,6 @@ module.exports = function serialize(obj, options) {
return infinities[valueIndex];
}

if (type === 'B') {
return "BigInt(\"" + bigInts[valueIndex] + "\")";
}

var fn = functions[valueIndex];

return serializeFunc(fn);
Expand Down
18 changes: 0 additions & 18 deletions test/unit/serialize.js
Expand Up @@ -414,24 +414,6 @@ describe('serialize( obj )', function () {
});
});

describe('BigInt', function () {
it('should serialize BigInt', function () {
var b = BigInt(9999);
expect(serialize(b)).to.equal('BigInt("9999")');
expect(serialize({t: [b]})).to.be.a('string').equal('{"t":[BigInt("9999")]}');
});

it('should deserialize BigInt', function () {
var d = eval(serialize(BigInt(9999)));
expect(d).to.be.a('BigInt');
expect(d.toString()).to.equal('9999');
});

it('should throw error for invalid bigint', function () {
expect(() => serialize(BigInt('abc'))).to.throw(Error);
});
});

describe('XSS', function () {
it('should encode unsafe HTML chars to Unicode', function () {
expect(serialize('</script>')).to.equal('"\\u003C\\u002Fscript\\u003E"');
Expand Down

0 comments on commit 7cee7e4

Please sign in to comment.