Skip to content

Build your personal knowledge base with Trilium Notes

test(search): group the entity assertions into single cases

sxh313b7f414260fb8
diff --git a/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.spec.ts b/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.spec.ts
index d2bb941f41..630ad28ed2 100644
--- a/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.spec.ts
+++ b/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.spec.ts
@@ -158,9 +158,28 @@ describe("Text (HTML) preprocessing", () => {
expect(result).toContain("a 1984 science fiction film.");
});
+ it("makes the searchable body the text the editor displays", () => {
+ // `extractContentSnippet()` decodes the same set to render a hit, so the spelling on screen
+ // is what a query has to be able to reach.
+ const ampersand = "<p>AT&amp;T reported earnings.</p>";
+ const entities = "<p>if a &lt; b &amp;&amp; b &gt; c, then&nbsp;done</p>";
+ const href = `<p>see <a href="https://example.com/?a=1&amp;b=2">docs</a></p>`;
+ const shown = "<p>use &amp;amp; to write one</p>";
+
+ expect(preprocessContent(ampersand, type, mime)).toEqual("at&t reported earnings.");
+ expect(preprocessContent(entities, type, mime)).toEqual("if a < b && b > c, then done");
+ expect(preprocessContent(href, type, mime)).toContain("https://example.com/?a=1&b=2");
+ // Decoded once: this body shows "&amp;", where a second pass would leave a bare "&".
+ expect(preprocessContent(shown, type, mime)).toContain("use &amp; to write one");
+ });
+
it("keeps the markup but still unescapes entities when raw is requested", () => {
- const result = preprocessContent("<p>Hello&nbsp;world</p>", type, mime, true);
- expect(result).toEqual("<p>hello world</p>");
+ const spacing = preprocessContent("<p>Hello&nbsp;world</p>", type, mime, true);
+ // `note.rawContent` searches the stored markup, so the basic entities stay encoded there.
+ const markup = preprocessContent("<p>AT&amp;T</p>", type, mime, true);
+
+ expect(spacing).toEqual("<p>hello world</p>");
+ expect(markup).toEqual("<p>at&amp;t</p>");
});
});
@@ -191,37 +210,4 @@ describe("LLM chat preprocessing", () => {
});
expect(preprocessContent(chat, type, mime)).toEqual("what is a branch? a parent-child link.");
});
-});
-
-describe("HTML entity decoding", () => {
- const type: NoteType = "text";
- const mime = "text/html";
-
- it("makes the text the editor displays searchable", () => {
- // `extractContentSnippet()` decodes these entities to render a hit, so the same spelling
- // is what a query has to match.
- const entities = "<p>if a &lt; b &amp;&amp; b &gt; c, then&nbsp;done</p>";
-
- expect(preprocessContent("<p>AT&amp;T reported earnings.</p>", type, mime))
- .toEqual("at&t reported earnings.");
- expect(preprocessContent(entities, type, mime)).toEqual("if a < b && b > c, then done");
- });
-
- it("decodes an entity-encoded query separator inside an anchor's href", () => {
- const html = `<p>see <a href="https://example.com/?a=1&amp;b=2">docs</a></p>`;
-
- expect(preprocessContent(html, type, mime)).toContain("https://example.com/?a=1&b=2");
- });
-
- it("decodes once, so a body showing an entity is still found by what it shows", () => {
- // This body displays "&amp;"; a second decode would leave a bare "&" and stop matching the
- // characters the note shows.
- expect(preprocessContent("<p>use &amp;amp; to write one</p>", type, mime))
- .toContain("use &amp; to write one");
- });
-
- it("keeps a raw content search against the stored markup", () => {
- // `note.rawContent` is the blob as written, entities and tags included.
- expect(preprocessContent("<p>AT&amp;T</p>", type, mime, true)).toEqual("<p>at&amp;t</p>");
- });
});
\ No newline at end of file
diff --git a/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.ts b/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.ts
index 1632e193f1..4c4b02517a 100644
--- a/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.ts
+++ b/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.ts
@@ -20,9 +20,8 @@ export default function preprocessContent(rawContent: string | Uint8Array, type:
// Content size already filtered at DB level, safe to process
content = stripTags(content);
- // The stored body holds entities where the editor shows characters, so decoding is what
- // makes the searchable text the displayed one. Injected link text arrives already
- // decoded, so this runs before it is appended and never twice over the same characters.
+ // The body is decoded so a query can reach the text the editor shows, and before the
+ // injected link text is appended, since that arrives decoded already.
content = unescapeHtml(content);
if (injectedText) {
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 f4b9200299..a53a2f4916 100644
--- a/packages/trilium-core/src/services/search/services/search.spec.ts
+++ b/packages/trilium-core/src/services/search/services/search.spec.ts
@@ -1177,20 +1177,14 @@ describe("Search", () => {
}
it("finds a body by the text the editor shows for it", () => {
- // This body reads "AT&T reported R&D spend, where a<b held." on screen, and that is the
- // wording the result card prints back, so a query in that shape has to reach the body.
- const telco = bodyNote("Telco", "<p>AT&amp;T reported R&amp;D spend, where a&lt;b held.</p>");
+ // The first body reads "AT&T and R&D, where a<b." on screen; the second displays
+ // "&amp;" and "&lt;", which a second decode would turn into "&" and "<".
+ const telco = bodyNote("Telco", "<p>AT&amp;T and R&amp;D, where a&lt;b.</p>");
+ const literal = bodyNote("Literal", "<p>write &amp;amp;t rather than &amp;lt;</p>");
expect(finds("AT&T", telco.noteId)).toBe(true);
expect(finds("R&D", telco.noteId)).toBe(true);
expect(finds("a<b", telco.noteId)).toBe(true);
- });
-
- it("decodes once, so a body showing an entity is found by what it shows", () => {
- // The body displays "&amp;" and "&lt;". A second decode would turn the second one into
- // a bare "<", which is not what the note says.
- const literal = bodyNote("Literal", "<p>write &amp;amp;t rather than &amp;lt;</p>");
-
expect(finds("&lt;", literal.noteId)).toBe(true);
expect(finds("at<t", literal.noteId)).toBe(false);
});