Skip to content

Commit

Permalink
Fix #clearPrefetchCache regex namespace bug. Closes #771.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Harding committed Jul 8, 2014
1 parent 9e6f132 commit c20a7ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bloodhound/persistent_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var PersistentStorage = (function() {
function PersistentStorage(namespace) {
this.prefix = ['__', namespace, '__'].join('');
this.ttlKey = '__ttl__';
this.keyMatcher = new RegExp('^' + this.prefix);
this.keyMatcher = new RegExp('^' + _.escapeRegExChars(this.prefix));
}

// instance methods
Expand Down
10 changes: 10 additions & 0 deletions test/persistent_storage_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ describe('PersistentStorage', function() {
});

describe('#clear', function() {
it('should work with namespaces that contain regex characters', function() {
engine = new PersistentStorage('ns?()');
engine.set('key1', 'val1');
engine.set('key2', 'val2');
engine.clear();

expect(engine.get('key1')).toEqual(undefined);
expect(engine.get('key2')).toEqual(undefined);
});

it('should remove all keys that exist in namespace of engine', function() {
engine.set('key1', 'val1');
engine.set('key2', 'val2');
Expand Down

0 comments on commit c20a7ec

Please sign in to comment.