diff --git a/src/pat/navigation/navigation.js b/src/pat/navigation/navigation.js index bc2af7410..5ecb3162d 100644 --- a/src/pat/navigation/navigation.js +++ b/src/pat/navigation/navigation.js @@ -207,7 +207,12 @@ export default Base.extend({ * @returns {String} - The prepared url. */ prepare_url(url) { - return url?.replace("/view", "").replaceAll("@@", "").replace(/\/$/, ""); + return url + ?.replace("/view", "") // Remove Plone-specific default view. + .replaceAll("@@", "") // Remove Plone-specific @@ identifier of views. + .split("?")[0] // Remove query string. + .split("#")[0] // Remove hash. + .replace(/\/$/, ""); // Remove trailing slash. }, /** diff --git a/src/pat/navigation/navigation.test.js b/src/pat/navigation/navigation.test.js index c68cdb9fc..23ee60bfe 100644 --- a/src/pat/navigation/navigation.test.js +++ b/src/pat/navigation/navigation.test.js @@ -289,7 +289,7 @@ describe("3 - Navigation pattern tests - Mark items based on URL", () => { `; - set_url("https://patternslib.com/"); + set_url("https://patternslib.com/?a=1&b=2#hash"); const instance = new Pattern(document.querySelector(".pat-navigation")); @@ -315,6 +315,30 @@ describe("3 - Navigation pattern tests - Mark items based on URL", () => { expect(document.querySelectorAll(".inPath").length).toBe(0); expect(document.querySelector(".current a")).toBe(it1); + // Check query string + instance.clear_items(); + instance.mark_items_url("https://patternslib.com/path1?a=1&b=2"); + + expect(document.querySelectorAll(".current").length).toBe(2); + expect(document.querySelectorAll(".inPath").length).toBe(0); + expect(document.querySelector(".current a")).toBe(it1); + + // Check hash + instance.clear_items(); + instance.mark_items_url("https://patternslib.com/path1/#hash"); + + expect(document.querySelectorAll(".current").length).toBe(2); + expect(document.querySelectorAll(".inPath").length).toBe(0); + expect(document.querySelector(".current a")).toBe(it1); + + // Check query string and hash + instance.clear_items(); + instance.mark_items_url("https://patternslib.com/path1?a=1&b=2#hash"); + + expect(document.querySelectorAll(".current").length).toBe(2); + expect(document.querySelectorAll(".inPath").length).toBe(0); + expect(document.querySelector(".current a")).toBe(it1); + instance.clear_items(); instance.mark_items_url("https://patternslib.com/path2");