detect attempts to compare between labels (only with constants is possible)

This commit is contained in:
zadam 2020-07-20 23:27:30 +02:00
parent 4e5ddaf7d1
commit f03e4bc7d7
4 changed files with 47 additions and 4 deletions

6
package-lock.json generated
View file

@ -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"

View file

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

View file

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

View file

@ -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 === '=') {