Skip to content

Commit

Permalink
Add tests to make sure no invalid function names get exported
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Bridgewater committed Jun 1, 2016
1 parent 1487760 commit 7eaba8c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

## v.2.6.1 - 02 Jun, 2016

Bugfixes

- Fixed invalid function name being exported

## v.2.6.0 - 01 Jun, 2016

In addition to the pre-releases the following changes exist in v.2.6.0:
Expand Down
3 changes: 3 additions & 0 deletions lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var changeFunctionName = (function () {
// that provided a functionality to add new commands to the client

commands.list.forEach(function (command) {

// Some rare Redis commands use special characters in their command name
// Convert those to a underscore to prevent using invalid function names
var commandName = command.replace(/(?:^([0-9])|[^a-zA-Z0-9_$])/g, '_$1');

// Do not override existing functions
Expand Down
11 changes: 10 additions & 1 deletion test/node_redis.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var helper = require('./helper');
var utils = require('../lib/utils');
var fork = require('child_process').fork;
var redis = config.redis;
var client;

describe('The node_redis client', function () {

Expand All @@ -29,10 +30,18 @@ describe('The node_redis client', function () {
});
});

it('convert minus to underscore in Redis function names', function (done) {
var names = Object.keys(redis.RedisClient.prototype);
client = redis.createClient();
for (var i = 0; i < names.length; i++) {
assert(/^([a-zA-Z_][a-zA-Z_0-9]*)?$/.test(client[names[i]].name));
}
client.quit(done);
});

helper.allTests(function (parser, ip, args) {

describe('using ' + parser + ' and ' + ip, function () {
var client;

afterEach(function () {
client.end(true);
Expand Down

0 comments on commit 7eaba8c

Please sign in to comment.