Skip to content

Commit

Permalink
Fix issue with false query parameter detection on URLs with no search…
Browse files Browse the repository at this point in the history
… parameters
  • Loading branch information
CookieCookson committed Sep 24, 2023
1 parent 0d7fcb3 commit 7c400be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function getSearchQueryParamsAsObject(str: string): {
[key: string]: any;
} {
const obj: { [key: string]: any } = {};
if (str.indexOf("?") === -1) return obj;
let queryString = str.substring(str.indexOf("?"));
queryString = queryString.split("#").shift();
if (!queryString) return obj;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { getSearchQueryParamsAsObject } from "./getSearchQueryParamsAsObject";
import { Actor } from "../../XAPI";

test("handles url with no query parameters", () => {
return expect(
Object.keys(getSearchQueryParamsAsObject("http://localhost:1234/")).length
).toEqual(0);
});

test("handles empty querystring", () => {
return expect(getSearchQueryParamsAsObject("")).toMatchObject({});
return expect(Object.keys(getSearchQueryParamsAsObject("")).length).toEqual(
0
);
});

test("converts querystring into object", () => {
Expand Down

0 comments on commit 7c400be

Please sign in to comment.