Skip to content

Commit 86b9de4

Browse files
committed
adapt query params
1 parent 9a146c7 commit 86b9de4

2 files changed

Lines changed: 15 additions & 20 deletions

File tree

packages/core/src/utils/data-collection/filterQueryParams.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@ import type { CollectBehavior } from '../../types/datacollection';
22
import { FILTERED_VALUE as FILTERED } from './filtering-snippets';
33
import { filterKeyValueData } from './filterKeyValueData';
44

5-
function parseQueryParams(queryString: string): Record<string, string> | undefined {
6-
try {
7-
const params = new URLSearchParams(queryString);
8-
const result: Record<string, string> = {};
9-
params.forEach((value, key) => {
10-
result[key] = value;
11-
});
12-
return Object.keys(result).length > 0 ? result : undefined;
13-
} catch {
14-
return undefined;
15-
}
16-
}
17-
185
/**
196
* Filters a query parameter string according to a `CollectBehavior`.
207
*
@@ -26,11 +13,19 @@ export function filterQueryParams(queryString: string, behavior: CollectBehavior
2613
return {};
2714
}
2815

29-
const parsed = parseQueryParams(queryString);
16+
try {
17+
const params = new URLSearchParams(queryString);
18+
const parsed: Record<string, string> = {};
19+
params.forEach((value, key) => {
20+
parsed[key] = value;
21+
});
3022

31-
if (parsed == null) {
23+
if (Object.keys(parsed).length === 0) {
24+
return {};
25+
}
26+
27+
return filterKeyValueData(parsed, behavior);
28+
} catch {
3229
return FILTERED;
3330
}
34-
35-
return filterKeyValueData(parsed, behavior);
3631
}

packages/core/test/lib/utils/data-collection/filterQueryParams.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ describe('filterQueryParams', () => {
6262
});
6363
});
6464

65-
describe('unparseable input', () => {
66-
it('returns [Filtered] for empty string', () => {
67-
expect(filterQueryParams('', true)).toBe('[Filtered]');
65+
describe('empty input', () => {
66+
it('returns empty record for empty string', () => {
67+
expect(filterQueryParams('', true)).toEqual({});
6868
});
6969
});
7070

0 commit comments

Comments
 (0)