Skip to content

Build your personal knowledge base with Trilium Notes

fix(client): match the query string before treating a URL as the app's own

matt wilkiee5f4d6dce58e
diff --git a/apps/client/src/services/link.spec.ts b/apps/client/src/services/link.spec.ts
index 8087d66545..e30c6c6610 100644
--- a/apps/client/src/services/link.spec.ts
+++ b/apps/client/src/services/link.spec.ts
@@ -177,6 +177,12 @@ describe("parseNavigationStateFromUrl", () => {
.toStrictEqual({});
expect(parseNavigationStateFromUrl("https://host/wiki/Page?x=1#root/WWaBNf3SSA1b", desktop))
.toStrictEqual({});
+
+ // A different query string, such as the `?print` entry point, is an external document too.
+ expect(parseNavigationStateFromUrl("https://host/?print#root/WWaBNf3SSA1b", new URL("https://host/")))
+ .toStrictEqual({});
+ expect(parseNavigationStateFromUrl("https://host/?print#root/WWaBNf3SSA1b", desktop))
+ .toStrictEqual({});
});
it("compares against window.location by default", () => {
diff --git a/apps/client/src/services/link.ts b/apps/client/src/services/link.ts
index b099e49368..17cea56ff1 100644
--- a/apps/client/src/services/link.ts
+++ b/apps/client/src/services/link.ts
@@ -439,11 +439,11 @@ export function parseNavigationStateFromUrl(
};
}
-/** Whether `url` addresses the document at `location`, ignoring the query string and the hash. */
+/** Whether `url` addresses the document at `location`, including its query string, ignoring the hash. */
function isSameDocumentUrl(url: string, hashIdx: number, location: UrlParts) {
- const [ documentUrl ] = url.slice(0, hashIdx).split("?");
+ const documentUrl = url.slice(0, hashIdx);
- return documentUrl === `${location.protocol}//${location.host}${location.pathname}`;
+ return documentUrl === `${location.protocol}//${location.host}${location.pathname}${location.search}`;
}
/** Iterates the `name=value` pairs of a hash's parameter string, decoding both sides. */