Skip to content

Commit 055d130

Browse files
committed
fix: allow prefixes with multiple semicolons & add test
1 parent 510e57f commit 055d130

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { normalizePrefixGlob } from '../normalizePrefixGlob';
2+
3+
describe('normalizePrefixGlob', () => {
4+
it('check simple mask', () => {
5+
expect(normalizePrefixGlob('bull*')).toBe('bull*:*:meta');
6+
expect(normalizePrefixGlob('bull')).toBe('bull:*:meta');
7+
});
8+
9+
it('check mask with queue name prefix', () => {
10+
expect(normalizePrefixGlob('bull:metrics*')).toBe('bull:metrics*:meta');
11+
});
12+
13+
it('check mask with queue name', () => {
14+
expect(normalizePrefixGlob('bull:metrics')).toBe('bull:metrics:meta');
15+
});
16+
17+
it('check mask with prefix which contains semicolons', () => {
18+
expect(normalizePrefixGlob('my:service:bull:metrics')).toBe('my:service:bull:metrics:meta');
19+
});
20+
});

src/helpers/normalizePrefixGlob.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export function normalizePrefixGlob(prefixGlob: string): string {
22
let prefixGlobNorm = prefixGlob;
3-
const nameCase = prefixGlobNorm.split(':').length - 1;
4-
if (nameCase >= 2) {
5-
prefixGlobNorm = prefixGlobNorm.split(':').slice(0, 2).join(':') + ':';
6-
} else if (nameCase === 1) {
3+
const nameCase = prefixGlobNorm.split(':');
4+
if (nameCase.length >= 3) {
5+
prefixGlobNorm = nameCase.filter((s) => s !== '').join(':') + ':';
6+
} else if (nameCase.length === 2) {
77
prefixGlobNorm += prefixGlobNorm.endsWith(':') ? '*:' : ':';
88
} else {
99
prefixGlobNorm += ':*:';

0 commit comments

Comments
 (0)