Skip to content

Build your personal knowledge base with Trilium Notes

fix(search): keep commas inside quoted operands so label values like #geolocation="48.8583,2.2945" can be matched

unknown80f10dfa90de
diff --git a/packages/trilium-core/src/services/search/services/lex.spec.ts b/packages/trilium-core/src/services/search/services/lex.spec.ts
index 668522b18d..1682a8d9a3 100644
--- a/packages/trilium-core/src/services/search/services/lex.spec.ts
+++ b/packages/trilium-core/src/services/search/services/lex.spec.ts
@@ -20,6 +20,13 @@ describe("Lexer fulltext", () => {
expect(lex("'i can use \" or ` or #~=*' without problem").fulltextTokens.map((t) => t.token)).toEqual(['i can use " or ` or #~=*', "without", "problem"]);
});
+ it("commas are noise in fulltext but kept inside quotes", () => {
+ expect(lex("europe, austria").fulltextTokens.map((t) => t.token)).toEqual(["europe", "austria"]);
+
+ // Quoted values must survive verbatim — e.g. the Geo Map manual's #geolocation="48.8583,2.2945".
+ expect(lex("'48.8583,2.2945'").fulltextTokens.map((t) => t.token)).toEqual(["48.8583,2.2945"]);
+ });
+
it("I can use backslash to escape quotes", () => {
expect(lex('hello \\"world\\"').fulltextTokens.map((t) => t.token)).toEqual(["hello", '"world"']);
@@ -106,6 +113,20 @@ describe("Lexer expression", () => {
]);
});
+ it("keeps commas inside a quoted operand", () => {
+ // The Geo Map manual stores coordinates as #geolocation="48.8583,2.2945"; the lexer used
+ // to strip the comma even inside quotes, making the stored value unreachable (#11132).
+ expect(lex('#geolocation="48.8583,2.2945"').expressionTokens.map((t) => t.token)).toEqual(
+ ["#geolocation", "=", "48.8583,2.2945"]
+ );
+ expect(lex("#geolocation='48.8583,2.2945'").expressionTokens.map((t) => t.token)).toEqual(
+ ["#geolocation", "=", "48.8583,2.2945"]
+ );
+
+ const quoted = lex('#geolocation="48.8583,2.2945"').expressionTokens[2];
+ expect(quoted.inQuotes).toBe(true);
+ });
+
it("simple label operator with param without quotes", () => {
expect(lex("#label*=*text").expressionTokens).toEqual([
{ token: "#label", inQuotes: false, startIndex: 0, endIndex: 5 },
diff --git a/packages/trilium-core/src/services/search/services/lex.ts b/packages/trilium-core/src/services/search/services/lex.ts
index 2fcd99ca2a..ff536f5d07 100644
--- a/packages/trilium-core/src/services/search/services/lex.ts
+++ b/packages/trilium-core/src/services/search/services/lex.ts
@@ -122,7 +122,9 @@ function lex(str: string) {
}
}
- if (chr === ",") {
+ // Commas are stripped as fulltext noise, but not inside quotes — a quoted operand
+ // (e.g. #geolocation="48.8583,2.2945") must keep the exact value the user stored.
+ if (chr === "," && !quotes) {
continue;
}
diff --git a/packages/trilium-core/src/services/search/services/search.spec.ts b/packages/trilium-core/src/services/search/services/search.spec.ts
index 7eb1a774ac..160b65603b 100644
--- a/packages/trilium-core/src/services/search/services/search.spec.ts
+++ b/packages/trilium-core/src/services/search/services/search.spec.ts
@@ -112,6 +112,26 @@ describe("Search", () => {
expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
});
+ it("label comparison with a comma in a quoted value", () => {
+ rootNote.child(note("Eiffel Tower").label("geolocation", "48.8583,2.2945")).child(note("Charles Bridge").label("geolocation", "50.0865,14.4114"));
+
+ const searchContext = new SearchContext();
+
+ // The Geo Map manual documents exactly this form; the lexer used to strip the comma
+ // inside the quotes, so the stored value could never be matched (#11132).
+ let searchResults = searchService.findResultsWithQuery('#geolocation="48.8583,2.2945"', searchContext);
+ expect(searchResults.length).toEqual(1);
+ expect(findNoteByTitle(searchResults, "Eiffel Tower")).toBeTruthy();
+
+ searchResults = searchService.findResultsWithQuery("#geolocation='50.0865,14.4114'", searchContext);
+ expect(searchResults.length).toEqual(1);
+ expect(findNoteByTitle(searchResults, "Charles Bridge")).toBeTruthy();
+
+ // A quoted value that matches no stored value still returns nothing.
+ searchResults = searchService.findResultsWithQuery('#geolocation="48.8583"', searchContext);
+ expect(searchResults.length).toEqual(0);
+ });
+
it("label comparison with full syntax", () => {
rootNote.child(note("Europe").child(note("Austria").label("capital", "Vienna")).child(note("Czech Republic").label("capital", "Prague")));