mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
detect attempts to compare between labels (only with constants is possible)
This commit is contained in:
parent
4e5ddaf7d1
commit
f03e4bc7d7
6
package-lock.json
generated
6
package-lock.json
generated
@ -5839,9 +5839,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"open": {
|
"open": {
|
||||||
"version": "7.0.4",
|
"version": "7.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/open/-/open-7.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/open/-/open-7.1.0.tgz",
|
||||||
"integrity": "sha512-brSA+/yq+b08Hsr4c8fsEW2CRzk1BmfN3SAK/5VCHQ9bdoZJ4qa/+AfR0xHjlbbZUyPkUHs1b8x1RqdyZdkVqQ==",
|
"integrity": "sha512-lLPI5KgOwEYCDKXf4np7y1PBEkj7HYIyP2DY8mVDRnx0VIIu6bNrRB0R66TuO7Mack6EnTNLm4uvcl1UoklTpA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"is-docker": "^2.0.0",
|
"is-docker": "^2.0.0",
|
||||||
"is-wsl": "^2.1.1"
|
"is-wsl": "^2.1.1"
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
"mime-types": "2.1.27",
|
"mime-types": "2.1.27",
|
||||||
"multer": "1.4.2",
|
"multer": "1.4.2",
|
||||||
"node-abi": "2.18.0",
|
"node-abi": "2.18.0",
|
||||||
"open": "7.0.4",
|
"open": "7.1.0",
|
||||||
"portscanner": "2.2.0",
|
"portscanner": "2.2.0",
|
||||||
"rand-token": "1.0.1",
|
"rand-token": "1.0.1",
|
||||||
"rcedit": "2.2.0",
|
"rcedit": "2.2.0",
|
||||||
|
@ -188,4 +188,41 @@ describe("Invalid tokens", () => {
|
|||||||
|
|
||||||
expect(parsingContext.error).toEqual('Misplaced or incomplete expression "="')
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -159,6 +159,12 @@ function getExpression(tokens, parsingContext, level = 0) {
|
|||||||
let operator = tokens[i + 1].token;
|
let operator = tokens[i + 1].token;
|
||||||
const comparedValue = tokens[i + 2].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);
|
parsingContext.highlightedTokens.push(comparedValue);
|
||||||
|
|
||||||
if (parsingContext.fuzzyAttributeSearch && operator === '=') {
|
if (parsingContext.fuzzyAttributeSearch && operator === '=') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user