mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
fix(ui): deduplicate filter in query args
If we get same filter value multiple times we should only use it once
This commit is contained in:
@@ -46,8 +46,11 @@ function DecodeLocationSearch(searchString) {
|
||||
if (parsed.q === "") {
|
||||
params.q = [];
|
||||
} else if (Array.isArray(parsed.q)) {
|
||||
// filter out empty strings, so 'q=' doesn't end up [""] but rather []
|
||||
params.q = parsed.q.filter(v => v !== "");
|
||||
// first filter out duplicates
|
||||
// then filter out empty strings, so 'q=' doesn't end up [""] but rather []
|
||||
params.q = parsed.q
|
||||
.filter((v, i) => parsed.q.indexOf(v) === i)
|
||||
.filter(v => v !== "");
|
||||
} else {
|
||||
params.q = [parsed.q];
|
||||
}
|
||||
|
||||
@@ -181,6 +181,13 @@ describe("DecodeLocationSearch", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("no value q[]=&q[]= search param is decoded correctly", () => {
|
||||
expect(DecodeLocationSearch("?q=")).toMatchObject({
|
||||
defaultsUsed: false,
|
||||
params: { q: [] }
|
||||
});
|
||||
});
|
||||
|
||||
it("single value q=foo search param is decoded correctly", () => {
|
||||
expect(DecodeLocationSearch("?q=foo")).toMatchObject({
|
||||
defaultsUsed: false,
|
||||
@@ -201,6 +208,20 @@ describe("DecodeLocationSearch", () => {
|
||||
params: { q: ["foo", "bar"] }
|
||||
});
|
||||
});
|
||||
|
||||
it("multi value q[]=foo&q[]=bar&q[]=foo search param is decoded correctly", () => {
|
||||
expect(DecodeLocationSearch("?q[]=foo&q[]=bar&q[]=foo")).toMatchObject({
|
||||
defaultsUsed: false,
|
||||
params: { q: ["foo", "bar"] }
|
||||
});
|
||||
});
|
||||
|
||||
it("multi value q[]=foo&q[]=&q[]=foo search param is decoded correctly", () => {
|
||||
expect(DecodeLocationSearch("?q[]=foo&q[]=&q[]=foo")).toMatchObject({
|
||||
defaultsUsed: false,
|
||||
params: { q: ["foo"] }
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("UpdateLocationSearch", () => {
|
||||
|
||||
Reference in New Issue
Block a user