1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00
Not inheriting from the prototype is a BC
This commit is contained in:
Ruben Bridgewater
2016-05-25 22:52:31 +03:00
parent fe00bf271d
commit 55528d8b1b
5 changed files with 10 additions and 18 deletions

View File

@@ -11,6 +11,10 @@ Features
- The JS parser is from now on the new default as it is a lot faster than the hiredis parser - The JS parser is from now on the new default as it is a lot faster than the hiredis parser
- This is no BC as there is no changed behavior for the user at all but just a performance improvement. Explicitly requireing the Hiredis parser is still possible. - This is no BC as there is no changed behavior for the user at all but just a performance improvement. Explicitly requireing the Hiredis parser is still possible.
Bugfixes
- Reverted support for `__proto__` (v.2.6.0-2) to prevent and breaking change
Deprecations Deprecations
- The `parser` option is deprecated and should be removed. The built-in Javascript parser is a lot faster than the hiredis parser and has more features - The `parser` option is deprecated and should be removed. The built-in Javascript parser is a lot faster than the hiredis parser and has more features

View File

@@ -1,8 +0,0 @@
'use strict';
// Using a predefined object with this prototype is faster than calling `Object.create(null)` directly
// This is needed to make sure `__proto__` and similar reserved words can be used
function RawObject () {}
RawObject.prototype = Object.create(null);
module.exports = RawObject;

View File

@@ -1,7 +1,5 @@
'use strict'; 'use strict';
var RawObject = require('./rawObject');
// hgetall converts its replies to an Object. If the reply is empty, null is returned. // hgetall converts its replies to an Object. If the reply is empty, null is returned.
// These function are only called with internal data and have therefore always the same instanceof X // These function are only called with internal data and have therefore always the same instanceof X
function replyToObject (reply) { function replyToObject (reply) {
@@ -9,7 +7,7 @@ function replyToObject (reply) {
if (reply.length === 0 || !(reply instanceof Array)) { if (reply.length === 0 || !(reply instanceof Array)) {
return null; return null;
} }
var obj = new RawObject(); var obj = {};
for (var i = 0; i < reply.length; i += 2) { for (var i = 0; i < reply.length; i += 2) {
obj[reply[i].toString('binary')] = reply[i + 1]; obj[reply[i].toString('binary')] = reply[i + 1];
} }

View File

@@ -22,12 +22,10 @@ describe("The 'hgetall' method", function () {
}); });
it('handles simple keys and values', function (done) { it('handles simple keys and values', function (done) {
client.hmset(['hosts', '__proto__', '1', 'another', '23', 'home', '1234'], helper.isString('OK')); client.hmset(['hosts', 'hasOwnProperty', '1', 'another', '23', 'home', '1234'], helper.isString('OK'));
client.HGETALL(['hosts'], function (err, obj) { client.HGETALL(['hosts'], function (err, obj) {
if (!/^v0\.10/.test(process.version)) { assert.strictEqual(3, Object.keys(obj).length);
assert.strictEqual(3, Object.keys(obj).length); assert.strictEqual('1', obj.hasOwnProperty.toString());
assert.strictEqual('1', obj.__proto__.toString()); // eslint-disable-line no-proto
}
assert.strictEqual('23', obj.another.toString()); assert.strictEqual('23', obj.another.toString());
assert.strictEqual('1234', obj.home.toString()); assert.strictEqual('1234', obj.home.toString());
done(err); done(err);

View File

@@ -204,8 +204,8 @@ describe('publish/subscribe', function () {
it('subscribe; close; resubscribe with prototype inherited property names', function (done) { it('subscribe; close; resubscribe with prototype inherited property names', function (done) {
var count = 0; var count = 0;
var channels = ['__proto__', 'channel 2']; var channels = ['channel 1', 'channel 2'];
var msg = ['hi from channel __proto__', 'hi from channel 2']; var msg = ['hi from channel 1', 'hi from channel 2'];
sub.on('message', function (channel, message) { sub.on('message', function (channel, message) {
var n = Math.max(count - 1, 0); var n = Math.max(count - 1, 0);