fix orderby with multiple labels, closes #4220

This commit is contained in:
zadam 2023-09-05 23:00:08 +02:00
parent f8e4a665bd
commit 7b662b04ff
2 changed files with 13 additions and 1 deletions

View File

@ -4,6 +4,9 @@ describe("Lexer fulltext", () => {
it("simple lexing", () => {
expect(lex("hello world").fulltextTokens.map(t => t.token))
.toEqual(["hello", "world"]);
expect(lex("hello, world").fulltextTokens.map(t => t.token))
.toEqual(["hello", "world"]);
});
it("use quotes to keep words together", () => {
@ -147,6 +150,11 @@ describe("Lexer expression", () => {
expect(lex(`# not(#capital) and note.noteId != "root"`).expressionTokens.map(t => t.token))
.toEqual(["#", "not", "(", "#capital", ")", "and", "note", ".", "noteid", "!=", "root"]);
});
it("order by multiple labels", () => {
expect(lex(`# orderby #a,#b`).expressionTokens.map(t => t.token))
.toEqual(["#", "orderby", "#a", ",", "#b"]);
});
});
describe("Lexer invalid queries and edge cases", () => {

View File

@ -11,7 +11,7 @@ function lex(str) {
let currentWord = '';
function isSymbolAnOperator(chr) {
return ['=', '*', '>', '<', '!', "-", "+", '%'].includes(chr);
return ['=', '*', '>', '<', '!', "-", "+", '%', ','].includes(chr);
}
function isPreviousSymbolAnOperator() {
@ -128,6 +128,10 @@ function lex(str) {
}
}
if (chr === ',') {
continue;
}
currentWord += chr;
}