Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
detect attempts to compare between labels (only with constants is possible)
zadamf03e4bc7d759
diff --git a/package-lock.json b/package-lock.jsonindex fc4def8379..374aa5fd58 100644--- a/package-lock.json+++ b/package-lock.json@@ -5839,9 +5839,9 @@}},"open": {- "version": "7.0.4",- "resolved": "https://registry.npmjs.org/open/-/open-7.0.4.tgz",- "integrity": "sha512-brSA+/yq+b08Hsr4c8fsEW2CRzk1BmfN3SAK/5VCHQ9bdoZJ4qa/+AfR0xHjlbbZUyPkUHs1b8x1RqdyZdkVqQ==",+ "version": "7.1.0",+ "resolved": "https://registry.npmjs.org/open/-/open-7.1.0.tgz",+ "integrity": "sha512-lLPI5KgOwEYCDKXf4np7y1PBEkj7HYIyP2DY8mVDRnx0VIIu6bNrRB0R66TuO7Mack6EnTNLm4uvcl1UoklTpA==","requires": {"is-docker": "^2.0.0","is-wsl": "^2.1.1"diff --git a/package.json b/package.jsonindex 2bef068579..f3f5778808 100644--- a/package.json+++ b/package.json@@ -54,7 +54,7 @@"mime-types": "2.1.27","multer": "1.4.2","node-abi": "2.18.0",- "open": "7.0.4",+ "open": "7.1.0","portscanner": "2.2.0","rand-token": "1.0.1","rcedit": "2.2.0",diff --git a/spec/search/parser.spec.js b/spec/search/parser.spec.jsindex 029d4f7e75..97c4dd3862 100644--- a/spec/search/parser.spec.js+++ b/spec/search/parser.spec.js@@ -188,4 +188,41 @@ describe("Invalid tokens", () => {expect(parsingContext.error).toEqual('Misplaced or incomplete expression "="')});++ it("comparison between labels is impossible", () => {+ let parsingContext = new ParsingContext();++ parser({+ fulltextTokens: [],+ expressionTokens: tokens("#first", "=", "#second"),+ parsingContext+ });++ expect(parsingContext.error).toEqual(`Error near token "#second", it's possible to compare with constant only.`);++ parsingContext = new ParsingContext();++ parser({+ fulltextTokens: [],+ expressionTokens: tokens("#first", "=", "note", ".", "relations", "second"),+ parsingContext+ });++ expect(parsingContext.error).toEqual(`Error near token "note", it's possible to compare with constant only.`);++ const rootExp = parser({+ fulltextTokens: [],+ expressionTokens: [+ { token: "#first", inQuotes: false },+ { token: "=", inQuotes: false },+ { token: "#second", inQuotes: true },+ ],+ parsingContext: new ParsingContext()+ });++ expect(rootExp.constructor.name).toEqual("LabelComparisonExp");+ expect(rootExp.attributeType).toEqual("label");+ expect(rootExp.attributeName).toEqual("first");+ expect(rootExp.comparator).toBeTruthy();+ });});diff --git a/src/services/search/parser.js b/src/services/search/parser.jsindex 641d1de09c..b18307d0f2 100644--- a/src/services/search/parser.js+++ b/src/services/search/parser.js@@ -159,6 +159,12 @@ function getExpression(tokens, parsingContext, level = 0) {let operator = tokens[i + 1].token;const comparedValue = tokens[i + 2].token;+ if (!tokens[i + 2].inQuotes+ && (comparedValue.startsWith('#') || comparedValue.startsWith('~') || comparedValue === 'note')) {+ parsingContext.addError(`Error near token "${comparedValue}", it's possible to compare with constant only.`);+ return;+ }+parsingContext.highlightedTokens.push(comparedValue);if (parsingContext.fuzzyAttributeSearch && operator === '=') {