diff --git a/ui/src/App.js b/ui/src/App.js index c501387a7..6ad6cc7e4 100644 --- a/ui/src/App.js +++ b/ui/src/App.js @@ -29,7 +29,7 @@ class App extends Component { let filters; // parse and decode request query args - const p = DecodeLocationSearch(); + const p = DecodeLocationSearch(window.location.search); // p.defaultsUsed means that unsee URI didn't have ?q=foo query args if (p.defaultsUsed) { diff --git a/ui/src/Stores/AlertStore.js b/ui/src/Stores/AlertStore.js index 912c36ec0..c2235b2ea 100644 --- a/ui/src/Stores/AlertStore.js +++ b/ui/src/Stores/AlertStore.js @@ -9,7 +9,9 @@ import qs from "qs"; // generate URL for the UI with a set of filters function FormatAPIFilterQuery(filters) { return qs.stringify( - Object.assign(DecodeLocationSearch().params, { q: filters }), + Object.assign(DecodeLocationSearch(window.location.search).params, { + q: filters + }), { encodeValuesOnly: true, // don't encode q[] indices: false // go-gin doesn't support parsing q[0]=foo&q[1]=bar @@ -23,12 +25,14 @@ function FormatUnseeBackendURI(path) { return `${uri}/${path}`; } -function DecodeLocationSearch() { +// takes the '?foo=bar&foo=baz' part of http://example.com?foo=bar&foo=baz +// and decodes it into a dict with some extra metadata +function DecodeLocationSearch(searchString) { let defaultsUsed = true; let params = { q: [] }; - if (window.location.search !== "") { - const parsed = qs.parse(window.location.search.split("?")[1]); + if (searchString !== "") { + const parsed = qs.parse(searchString.split("?")[1]); params = Object.assign(params, parsed); if (parsed.q !== undefined) { @@ -36,7 +40,8 @@ function DecodeLocationSearch() { if (parsed.q === "") { params.q = []; } else if (Array.isArray(parsed.q)) { - params.q = parsed.q; + // filter out empty strings, so 'q=' doesn't end up [""] but rather [] + params.q = parsed.q.filter(v => v !== ""); } else { params.q = [parsed.q]; }