1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

Ensure synthetic function names conform to naming requirements

The "restore-asking" function name is not valid and was causing co-redis (by way of its usage of thenify) to throw because thenify uses the function name to rewrite async functions with promises.

This PR will change the name of the "restore-asking" function to "restore_asking", which is valid.

This sanitation is a bit stricter than necessary, since it also sanitizes valid unicode characters, but it covers this module's potential use cases just fine.
This commit is contained in:
Dan MacTough
2016-06-01 13:15:00 -04:00
parent dffc27d83f
commit 68ca5c760b

View File

@@ -21,6 +21,7 @@ var changeFunctionName = (function () {
// that provided a functionality to add new commands to the client // that provided a functionality to add new commands to the client
commands.list.forEach(function (command) { commands.list.forEach(function (command) {
var commandName = command.replace(/(?:^([0-9])|[^a-zA-Z0-9_$])/g, '_$1');
// Do not override existing functions // Do not override existing functions
if (!RedisClient.prototype[command]) { if (!RedisClient.prototype[command]) {
@@ -59,7 +60,7 @@ commands.list.forEach(function (command) {
}; };
if (changeFunctionName) { if (changeFunctionName) {
Object.defineProperty(RedisClient.prototype[command], 'name', { Object.defineProperty(RedisClient.prototype[command], 'name', {
value: command value: commandName
}); });
} }
} }
@@ -102,7 +103,7 @@ commands.list.forEach(function (command) {
}; };
if (changeFunctionName) { if (changeFunctionName) {
Object.defineProperty(Multi.prototype[command], 'name', { Object.defineProperty(Multi.prototype[command], 'name', {
value: command value: commandName
}); });
} }
} }