You've already forked node-redis
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:
@@ -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
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user