Skip to content

Commit 68ca5c7

Browse files
committed
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.
1 parent dffc27d commit 68ca5c7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/commands.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var changeFunctionName = (function () {
2121
// that provided a functionality to add new commands to the client
2222

2323
commands.list.forEach(function (command) {
24+
var commandName = command.replace(/(?:^([0-9])|[^a-zA-Z0-9_$])/g, '_$1');
2425

2526
// Do not override existing functions
2627
if (!RedisClient.prototype[command]) {
@@ -59,7 +60,7 @@ commands.list.forEach(function (command) {
5960
};
6061
if (changeFunctionName) {
6162
Object.defineProperty(RedisClient.prototype[command], 'name', {
62-
value: command
63+
value: commandName
6364
});
6465
}
6566
}
@@ -102,7 +103,7 @@ commands.list.forEach(function (command) {
102103
};
103104
if (changeFunctionName) {
104105
Object.defineProperty(Multi.prototype[command], 'name', {
105-
value: command
106+
value: commandName
106107
});
107108
}
108109
}

0 commit comments

Comments
 (0)