Skip to content

Commit

Permalink
fix: protect merged static and dynamic tags from being duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
drwatsno committed Jan 23, 2020
1 parent 10202cc commit dabd053
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/storages/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ describe('BaseStorage', () => {
expect(value.expiresIn).toEqual(expect.any(Number));
});

it('set sets key to storage adapter with concatenated dynamic tags and simple tags', async () => {
await storage.set('test', '123', { tags: ['tag1'], getTags: (result) => [result]});
it('set sets key to storage adapter with uniq array of concatenated dynamic tags and simple tags', async () => {
await storage.set('test', '123', { tags: ['tag1', '123'], getTags: (result) => [result]});

const value = JSON.parse(testInterface.internalStorage['cache-test']);

Expand Down
3 changes: 2 additions & 1 deletion src/storages/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createHash } from 'crypto';
import isFunction from 'lodash/isFunction';
import uniq from 'lodash/uniq';
import { WriteOptions, Storage, StorageRecord, StorageRecordTag, StorageRecordValue } from '../storage';
import { StorageAdapter } from '../storage-adapter';
import serialize from '../serialize';
Expand Down Expand Up @@ -158,7 +159,7 @@ export class BaseStorage implements Storage {
throw new TypeError(`getTags should return an array of strings, got ${typeof dynamicTags}`);
}

const record = createRecord(key, value, tags.concat(dynamicTags).map(createTag), options);
const record = createRecord(key, value, uniq(tags.concat(dynamicTags)).map(createTag), options);

await this.adapter.set(
this.createKey(key),
Expand Down

0 comments on commit dabd053

Please sign in to comment.