Skip to content

Build your personal knowledge base with Trilium Notes

fix(link): search from URL not working (closes #1335)

Elian Doran79cc1cbf1772
diff --git a/src/public/app/services/link.spec.ts b/src/public/app/services/link.spec.ts
new file mode 100644
index 0000000000..984822a50b
--- /dev/null
+++ b/src/public/app/services/link.spec.ts
@@ -0,0 +1,9 @@
+import { describe, expect, it } from "vitest";
+import { parseNavigationStateFromUrl } from "./link.js";
+
+describe("Link", () => {
+ it("parses plain searchString", () => {
+ const output = parseNavigationStateFromUrl("http://localhost:8080/#?searchString=hello");
+ expect(output).toMatchObject({ searchString: "hello" });
+ });
+});
diff --git a/src/public/app/services/link.ts b/src/public/app/services/link.ts
index 8cda26fa55..c57ec54948 100644
--- a/src/public/app/services/link.ts
+++ b/src/public/app/services/link.ts
@@ -198,7 +198,7 @@ function calculateHash({ notePath, ntxId, hoistedNoteId, viewScope = {} }: NoteC
return hash;
}
-function parseNavigationStateFromUrl(url: string | undefined) {
+export function parseNavigationStateFromUrl(url: string | undefined) {
if (!url) {
return {};
}
@@ -209,11 +209,7 @@ function parseNavigationStateFromUrl(url: string | undefined) {
}
const hash = url.substr(hashIdx + 1); // strip also the initial '#'
- const [notePath, paramString] = hash.split("?");
-
- if (!notePath.match(/^[_a-z0-9]{4,}(\/[_a-z0-9]{4,})*$/i)) {
- return {};
- }
+ let [notePath, paramString] = hash.split("?");
const viewScope: ViewScope = {
viewMode: "default"
@@ -242,6 +238,10 @@ function parseNavigationStateFromUrl(url: string | undefined) {
}
}
+ if (!notePath.match(/^[_a-z0-9]{4,}(\/[_a-z0-9]{4,})*$/i)) {
+ return { searchString }
+ }
+
return {
notePath,
noteId: treeService.getNoteIdFromUrl(notePath),