Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/pat/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
},

/**
Expand Down
26 changes: 25 additions & 1 deletion src/pat/navigation/navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ describe("3 - Navigation pattern tests - Mark items based on URL", () => {
</nav>
`;

set_url("https://patternslib.com/");
set_url("https://patternslib.com/?a=1&b=2#hash");

const instance = new Pattern(document.querySelector(".pat-navigation"));

Expand All @@ -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");

Expand Down