1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

chore: guard against inherited properties

This commit is contained in:
Ruben Bridgewater
2017-05-27 01:01:42 +02:00
parent e33a642994
commit 8cca9ccf58
4 changed files with 24 additions and 13 deletions

View File

@@ -40,12 +40,14 @@ function RedisClient (options, stream) {
const cnxOptions = {} const cnxOptions = {}
/* istanbul ignore next: travis does not work with stunnel atm. Therefore the tls tests are skipped on travis */ /* istanbul ignore next: travis does not work with stunnel atm. Therefore the tls tests are skipped on travis */
for (const tlsOption in options.tls) { for (const tlsOption in options.tls) {
if (options.tls.hasOwnProperty(tlsOption)) {
cnxOptions[tlsOption] = options.tls[tlsOption] cnxOptions[tlsOption] = options.tls[tlsOption]
// Copy the tls options into the general options to make sure the address is set right // Copy the tls options into the general options to make sure the address is set right
if (tlsOption === 'port' || tlsOption === 'host' || tlsOption === 'path' || tlsOption === 'family') { if (tlsOption === 'port' || tlsOption === 'host' || tlsOption === 'path' || tlsOption === 'family') {
options[tlsOption] = options.tls[tlsOption] options[tlsOption] = options.tls[tlsOption]
} }
} }
}
if (stream) { if (stream) {
// The stream from the outside is used so no connection from this side is triggered but from the server this client should talk to // The stream from the outside is used so no connection from this side is triggered but from the server this client should talk to
// Reconnect etc won't work with this. This requires monkey patching to work, so it is not officially supported // Reconnect etc won't work with this. This requires monkey patching to work, so it is not officially supported
@@ -69,8 +71,10 @@ function RedisClient (options, stream) {
options.socketKeepalive = true options.socketKeepalive = true
} }
for (const command in options.renameCommands) { for (const command in options.renameCommands) {
if (options.renameCommands.hasOwnProperty(command)) {
options.renameCommands[command.toLowerCase()] = options.renameCommands[command] options.renameCommands[command.toLowerCase()] = options.renameCommands[command]
} }
}
options.returnBuffers = !!options.returnBuffers options.returnBuffers = !!options.returnBuffers
options.detectBuffers = !!options.detectBuffers options.detectBuffers = !!options.detectBuffers
// Override the detectBuffers setting if returnBuffers is active and print a warning // Override the detectBuffers setting if returnBuffers is active and print a warning

View File

@@ -42,6 +42,9 @@ module.exports = function createClient (portArg, hostArg, options) {
if (parsed.search !== '') { if (parsed.search !== '') {
var elem var elem
for (elem in parsed.query) { for (elem in parsed.query) {
if (!parsed.query.hasOwnProperty(elem)) {
continue
}
// If options are passed twice, only the parsed options will be used // If options are passed twice, only the parsed options will be used
if (elem in options) { if (elem in options) {
if (options[elem] === parsed.query[elem]) { if (options[elem] === parsed.query[elem]) {

View File

@@ -85,8 +85,10 @@ RedisClient.prototype.duplicate = function (options, callback) {
const existingOptions = utils.clone(this.options) const existingOptions = utils.clone(this.options)
options = utils.clone(options) options = utils.clone(options)
for (const elem in options) { for (const elem in options) {
if (options.hasOwnProperty(elem)) {
existingOptions[elem] = options[elem] existingOptions[elem] = options[elem]
} }
}
const client = new RedisClient(existingOptions) const client = new RedisClient(existingOptions)
client.selectedDb = this.selectedDb client.selectedDb = this.selectedDb
if (typeof callback === 'function') { if (typeof callback === 'function') {

View File

@@ -72,6 +72,7 @@ function onReady (client) {
if (!client.options.disableResubscribing && callbackCount) { if (!client.options.disableResubscribing && callbackCount) {
debug('Sending pub/sub onReady commands') debug('Sending pub/sub onReady commands')
for (const key in client.subscriptionSet) { for (const key in client.subscriptionSet) {
if (client.subscriptionSet.hasOwnProperty(key)) {
const command = key.slice(0, key.indexOf('_')) const command = key.slice(0, key.indexOf('_'))
const args = client.subscriptionSet[key] const args = client.subscriptionSet[key]
client[command]([args]).catch((err) => { client[command]([args]).catch((err) => {
@@ -81,6 +82,7 @@ function onReady (client) {
}) })
} }
} }
}
client.sendOfflineQueue() client.sendOfflineQueue()
client.emit('ready') client.emit('ready')
} }