Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #18 from lipsmack/bugfix/pattern-matching
Browse files Browse the repository at this point in the history
Correctly escape special characters in pattern matcher
  • Loading branch information
hdachev committed Mar 19, 2015
2 parents 0d69782 + 5b13f07 commit 3812347
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/backend.js
Expand Up @@ -145,7 +145,7 @@ var str2int = function (string) {
};

var pattern = function (string) {
string = string.replace(/[+{($^|.\\]/g, '\\' + '$0');
string = string.replace(/([+{($^|.\\])/g, '\\' + '$1');
string = string.replace(/(^|[^\\])([*?])/g, '$1.$2');
string = '^' + string + '$';

Expand Down
12 changes: 6 additions & 6 deletions test.js
Expand Up @@ -457,7 +457,7 @@ process.stdout.write('testing fakeredis ...\n\n');
sub3 = fake.createClient("pubsub-1"),

data = [ 0, [], [], [] ],
tcb1 = test("PUBSUB basics", null, [ 4, [ 'mych-alpha', 'mych-beta', 'mych-omega' ], [ 'mych-alpha', 'mych-beta' ], [ 'mych-alpha', 'mych-beta', 'what-what', 'mych-omega' ] ]),
tcb1 = test("PUBSUB basics", null, [ 4, [ 'my.ch-alpha', 'my.ch-beta', 'my.ch-omega' ], [ 'my.ch-alpha', 'my.ch-beta' ], [ 'my.ch-alpha', 'my.ch-beta', 'what-what', 'my.ch-omega' ] ]),

ord = [],
tcb2 = test("PUBSUB normal / sequence", null, [ 1, '*ch', 'pun', 1 ]),
Expand All @@ -469,9 +469,9 @@ process.stdout.write('testing fakeredis ...\n\n');
ord.push(data);
});

sub1.SUBSCRIBE("mych");
sub1.SUBSCRIBE("my.ch");
sub2.PSUBSCRIBE("*ch");
sub3.PSUBSCRIBE("my*", "what");
sub3.PSUBSCRIBE("my.*", "what");

try {
sub3.PUBLISH('fail', 'fail');
Expand All @@ -485,7 +485,7 @@ process.stdout.write('testing fakeredis ...\n\n');
data[1].push(channel + '-' + message);

if (message === 'alpha')
pub.PUBLISH('mych', 'beta', test('PUB2', null, 3));
pub.PUBLISH('my.ch', 'beta', test('PUB2', null, 3));
});

sub2.on('pmessage', function (pattern, channel, message) {
Expand All @@ -508,7 +508,7 @@ process.stdout.write('testing fakeredis ...\n\n');
});

sub2.PUBLISH('hello', 'world', test('PUB4 ignored', null, 0));
sub2.PUBLISH('mych', 'omega', test('PUB5 unsubed', null, 2));
sub2.PUBLISH('my.ch', 'omega', test('PUB5 unsubed', null, 2));
});

sub3.on('pmessage', function (pattern, channel, message) {
Expand All @@ -518,7 +518,7 @@ process.stdout.write('testing fakeredis ...\n\n');
var start = function (ch) {
data [ 0 ] ++;
if (data [ 0 ] === 4) {
pub.PUBLISH('mych', 'alpha', test('PUB1', null, 3));
pub.PUBLISH('my.ch', 'alpha', test('PUB1', null, 3));
}

if (ch === '*ch')
Expand Down

0 comments on commit 3812347

Please sign in to comment.