From 68ca5c760b4bd6f46201820277e3720b975d55c1 Mon Sep 17 00:00:00 2001 From: Dan MacTough Date: Wed, 1 Jun 2016 13:15:00 -0400 Subject: [PATCH] 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. --- lib/commands.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/commands.js b/lib/commands.js index 0082330..a64773e 100644 --- a/lib/commands.js +++ b/lib/commands.js @@ -21,6 +21,7 @@ var changeFunctionName = (function () { // that provided a functionality to add new commands to the client commands.list.forEach(function (command) { + var commandName = command.replace(/(?:^([0-9])|[^a-zA-Z0-9_$])/g, '_$1'); // Do not override existing functions if (!RedisClient.prototype[command]) { @@ -59,7 +60,7 @@ commands.list.forEach(function (command) { }; if (changeFunctionName) { Object.defineProperty(RedisClient.prototype[command], 'name', { - value: command + value: commandName }); } } @@ -102,7 +103,7 @@ commands.list.forEach(function (command) { }; if (changeFunctionName) { Object.defineProperty(Multi.prototype[command], 'name', { - value: command + value: commandName }); } }