Skip to content

Commit 1487760

Browse files
committed
Merge pull request #1076 from danmactough/use-safe-function-names
Ensure synthetic function names conform to naming requirements
2 parents dffc27d + 68ca5c7 commit 1487760

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)