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

This commit is contained in:
Elian Doran 2025-03-06 22:17:14 +02:00
parent 1ba6104e36
commit 79cc1cbf17
No known key found for this signature in database
2 changed files with 15 additions and 6 deletions

View File

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

View File

@ -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),