From d3f99c199aa24a6949749ca9974aacf65bfe7772 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Thu, 24 Oct 2024 18:30:32 +0200 Subject: [PATCH] fix issues with quotes --- src/libs/SearchParser/autocompleteParser.js | 270 ++++++++++++------ .../SearchParser/autocompleteParser.peggy | 23 +- src/libs/SearchParser/baseRules.peggy | 10 +- src/libs/SearchParser/searchParser.js | 240 ++++++++++------ src/libs/SearchParser/searchParser.peggy | 11 +- 5 files changed, 358 insertions(+), 196 deletions(-) diff --git a/src/libs/SearchParser/autocompleteParser.js b/src/libs/SearchParser/autocompleteParser.js index ed4a4e4e1afe..5fc13ac07f17 100644 --- a/src/libs/SearchParser/autocompleteParser.js +++ b/src/libs/SearchParser/autocompleteParser.js @@ -185,17 +185,19 @@ function peg$parse(input, options) { var peg$c7 = "expenseType"; var peg$c8 = "type"; var peg$c9 = "status"; - var peg$c10 = "!="; - var peg$c11 = ">="; - var peg$c12 = ">"; - var peg$c13 = "<="; - var peg$c14 = "<"; - var peg$c15 = "\""; + var peg$c10 = ","; + var peg$c11 = "!="; + var peg$c12 = ">="; + var peg$c13 = ">"; + var peg$c14 = "<="; + var peg$c15 = "<"; + var peg$c16 = "\""; var peg$r0 = /^[:=]/; - var peg$r1 = /^[^"\r\n]/; - var peg$r2 = /^[^ "\t\n\r]/; - var peg$r3 = /^[ \t\r\n]/; + var peg$r1 = /^[^ ,"\t\n\r]/; + var peg$r2 = /^[^"\r\n]/; + var peg$r3 = /^[^ ,\t\n\r]/; + var peg$r4 = /^[ \t\r\n]/; var peg$e0 = peg$otherExpectation("key"); var peg$e1 = peg$literalExpectation("in", false); @@ -208,20 +210,22 @@ function peg$parse(input, options) { var peg$e8 = peg$literalExpectation("expenseType", false); var peg$e9 = peg$literalExpectation("type", false); var peg$e10 = peg$literalExpectation("status", false); - var peg$e11 = peg$otherExpectation("operator"); - var peg$e12 = peg$classExpectation([":", "="], false, false); - var peg$e13 = peg$literalExpectation("!=", false); - var peg$e14 = peg$literalExpectation(">=", false); - var peg$e15 = peg$literalExpectation(">", false); - var peg$e16 = peg$literalExpectation("<=", false); - var peg$e17 = peg$literalExpectation("<", false); - var peg$e18 = peg$otherExpectation("quote"); - var peg$e19 = peg$literalExpectation("\"", false); - var peg$e20 = peg$classExpectation(["\"", "\r", "\n"], true, false); - var peg$e21 = peg$otherExpectation("word"); - var peg$e22 = peg$classExpectation([" ", "\"", "\t", "\n", "\r"], true, false); - var peg$e23 = peg$otherExpectation("whitespace"); - var peg$e24 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false); + var peg$e11 = peg$literalExpectation(",", false); + var peg$e12 = peg$otherExpectation("operator"); + var peg$e13 = peg$classExpectation([":", "="], false, false); + var peg$e14 = peg$literalExpectation("!=", false); + var peg$e15 = peg$literalExpectation(">=", false); + var peg$e16 = peg$literalExpectation(">", false); + var peg$e17 = peg$literalExpectation("<=", false); + var peg$e18 = peg$literalExpectation("<", false); + var peg$e19 = peg$otherExpectation("quote"); + var peg$e20 = peg$classExpectation([" ", ",", "\"", "\t", "\n", "\r"], true, false); + var peg$e21 = peg$literalExpectation("\"", false); + var peg$e22 = peg$classExpectation(["\"", "\r", "\n"], true, false); + var peg$e23 = peg$classExpectation([" ", ",", "\t", "\n", "\r"], true, false); + var peg$e24 = peg$otherExpectation("word"); + var peg$e25 = peg$otherExpectation("whitespace"); + var peg$e26 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false); var peg$f0 = function(ranges) { return { autocomplete, ranges }; }; var peg$f1 = function(filters) { return filters.filter(Boolean).flat(); }; @@ -241,21 +245,30 @@ function peg$parse(input, options) { ...value[value.length - 1], }; - return value.map(({ start, length }) => ({ - key, - start, - length, - })); + return value + .filter((filter) => filter.length > 0) + .map(({ start, length }) => ({ + key, + start, + length, + })); }; var peg$f3 = function() { autocomplete = null; }; - var peg$f4 = function(parts) { + var peg$f4 = function(parts, empty) { const ends = location(); const value = parts.flat(); + if (empty) { + value.push(""); + } let count = ends.start.offset; const result = []; value.forEach((filter) => { + let word = filter; + if (word.startsWith('"') && word.endsWith('"') && word.length >= 2) { + word = word.slice(1, -1); + } result.push({ - value: filter, + value: word, start: count, length: filter.length, }); @@ -269,10 +282,10 @@ function peg$parse(input, options) { var peg$f8 = function() { return "gt"; }; var peg$f9 = function() { return "lte"; }; var peg$f10 = function() { return "lt"; }; - var peg$f11 = function(chars) { return chars.join(""); }; - var peg$f12 = function(chars) { - return chars.join("").trim().split(",").filter(Boolean); + var peg$f11 = function(start, inner, end) { + return [...start, '"', ...inner, '"', ...end].join(""); }; + var peg$f12 = function(chars) { return chars.join("").trim(); }; var peg$f13 = function() { return "and"; }; var peg$currPos = options.peg$currPos | 0; var peg$savedPos = peg$currPos; @@ -648,30 +661,63 @@ function peg$parse(input, options) { } function peg$parseidentifier() { - var s0, s1, s2; + var s0, s1, s2, s3, s4; s0 = peg$currPos; - s1 = []; - s2 = peg$parsequotedString(); - if (s2 === peg$FAILED) { - s2 = peg$parsealphanumeric(); + s1 = peg$currPos; + s2 = []; + s3 = peg$parsequotedString(); + if (s3 === peg$FAILED) { + s3 = peg$parsealphanumeric(); } - if (s2 !== peg$FAILED) { - while (s2 !== peg$FAILED) { - s1.push(s2); - s2 = peg$parsequotedString(); - if (s2 === peg$FAILED) { - s2 = peg$parsealphanumeric(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 44) { + s4 = peg$c10; + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e11); } + } + if (s4 !== peg$FAILED) { + s4 = peg$parsequotedString(); + if (s4 === peg$FAILED) { + s4 = peg$parsealphanumeric(); } + if (s4 === peg$FAILED) { + peg$currPos = s3; + s3 = peg$FAILED; + } else { + s3 = s4; + } + } else { + s3 = s4; } - } else { + } + if (s2.length < 1) { + peg$currPos = s1; s1 = peg$FAILED; + } else { + s1 = s2; } if (s1 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 44) { + s2 = peg$c10; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e11); } + } + if (s2 === peg$FAILED) { + s2 = null; + } peg$savedPos = s0; - s1 = peg$f4(s1); + s0 = peg$f4(s1, s2); + } else { + peg$currPos = s0; + s0 = peg$FAILED; } - s0 = s1; return s0; } @@ -686,7 +732,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } + if (peg$silentFails === 0) { peg$fail(peg$e13); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -695,12 +741,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c10) { - s1 = peg$c10; + if (input.substr(peg$currPos, 2) === peg$c11) { + s1 = peg$c11; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e13); } + if (peg$silentFails === 0) { peg$fail(peg$e14); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -709,12 +755,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c11) { - s1 = peg$c11; + if (input.substr(peg$currPos, 2) === peg$c12) { + s1 = peg$c12; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e14); } + if (peg$silentFails === 0) { peg$fail(peg$e15); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -724,11 +770,11 @@ function peg$parse(input, options) { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 62) { - s1 = peg$c12; + s1 = peg$c13; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e15); } + if (peg$silentFails === 0) { peg$fail(peg$e16); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -737,12 +783,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c13) { - s1 = peg$c13; + if (input.substr(peg$currPos, 2) === peg$c14) { + s1 = peg$c14; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e16); } + if (peg$silentFails === 0) { peg$fail(peg$e17); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -752,11 +798,11 @@ function peg$parse(input, options) { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 60) { - s1 = peg$c14; + s1 = peg$c15; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e17); } + if (peg$silentFails === 0) { peg$fail(peg$e18); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -771,53 +817,89 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e11); } + if (peg$silentFails === 0) { peg$fail(peg$e12); } } return s0; } function peg$parsequotedString() { - var s0, s1, s2, s3; + var s0, s1, s2, s3, s4, s5, s6; peg$silentFails++; s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c15; + s1 = []; + s2 = input.charAt(peg$currPos); + if (peg$r1.test(s2)) { peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e19); } + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e20); } } - if (s1 !== peg$FAILED) { - s2 = []; - s3 = input.charAt(peg$currPos); - if (peg$r1.test(s3)) { + while (s2 !== peg$FAILED) { + s1.push(s2); + s2 = input.charAt(peg$currPos); + if (peg$r1.test(s2)) { peg$currPos++; } else { - s3 = peg$FAILED; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e20); } } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = input.charAt(peg$currPos); - if (peg$r1.test(s3)) { + } + if (input.charCodeAt(peg$currPos) === 34) { + s2 = peg$c16; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e21); } + } + if (s2 !== peg$FAILED) { + s3 = []; + s4 = input.charAt(peg$currPos); + if (peg$r2.test(s4)) { + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e22); } + } + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = input.charAt(peg$currPos); + if (peg$r2.test(s4)) { peg$currPos++; } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e20); } + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e22); } } } if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c15; + s4 = peg$c16; peg$currPos++; } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e19); } + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e21); } } - if (s3 !== peg$FAILED) { + if (s4 !== peg$FAILED) { + s5 = []; + s6 = input.charAt(peg$currPos); + if (peg$r3.test(s6)) { + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e23); } + } + while (s6 !== peg$FAILED) { + s5.push(s6); + s6 = input.charAt(peg$currPos); + if (peg$r3.test(s6)) { + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e23); } + } + } peg$savedPos = s0; - s0 = peg$f11(s2); + s0 = peg$f11(s1, s3, s5); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -829,7 +911,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e18); } + if (peg$silentFails === 0) { peg$fail(peg$e19); } } return s0; @@ -842,21 +924,21 @@ function peg$parse(input, options) { s0 = peg$currPos; s1 = []; s2 = input.charAt(peg$currPos); - if (peg$r2.test(s2)) { + if (peg$r3.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e22); } + if (peg$silentFails === 0) { peg$fail(peg$e23); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); s2 = input.charAt(peg$currPos); - if (peg$r2.test(s2)) { + if (peg$r3.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e22); } + if (peg$silentFails === 0) { peg$fail(peg$e23); } } } } else { @@ -870,7 +952,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e21); } + if (peg$silentFails === 0) { peg$fail(peg$e24); } } return s0; @@ -894,25 +976,25 @@ function peg$parse(input, options) { peg$silentFails++; s0 = []; s1 = input.charAt(peg$currPos); - if (peg$r3.test(s1)) { + if (peg$r4.test(s1)) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e24); } + if (peg$silentFails === 0) { peg$fail(peg$e26); } } while (s1 !== peg$FAILED) { s0.push(s1); s1 = input.charAt(peg$currPos); - if (peg$r3.test(s1)) { + if (peg$r4.test(s1)) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e24); } + if (peg$silentFails === 0) { peg$fail(peg$e26); } } } peg$silentFails--; s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e23); } + if (peg$silentFails === 0) { peg$fail(peg$e25); } return s0; } diff --git a/src/libs/SearchParser/autocompleteParser.peggy b/src/libs/SearchParser/autocompleteParser.peggy index 003d35485d69..bc96c86eb74d 100644 --- a/src/libs/SearchParser/autocompleteParser.peggy +++ b/src/libs/SearchParser/autocompleteParser.peggy @@ -39,11 +39,13 @@ defaultFilter ...value[value.length - 1], }; - return value.map(({ start, length }) => ({ - key, - start, - length, - })); + return value + .filter((filter) => filter.length > 0) + .map(({ start, length }) => ({ + key, + start, + length, + })); } freeTextFilter = _ identifier _ { autocomplete = null; } @@ -63,14 +65,21 @@ autocompleteKey "key" ) identifier - = parts:(quotedString / alphanumeric)+ { + = parts:(quotedString / alphanumeric)|1.., ","| empty:","? { const ends = location(); const value = parts.flat(); + if (empty) { + value.push(""); + } let count = ends.start.offset; const result = []; value.forEach((filter) => { + let word = filter; + if (word.startsWith('"') && word.endsWith('"') && word.length >= 2) { + word = word.slice(1, -1); + } result.push({ - value: filter, + value: word, start: count, length: filter.length, }); diff --git a/src/libs/SearchParser/baseRules.peggy b/src/libs/SearchParser/baseRules.peggy index 49f929bbe389..7605d888ba43 100644 --- a/src/libs/SearchParser/baseRules.peggy +++ b/src/libs/SearchParser/baseRules.peggy @@ -16,13 +16,13 @@ operator "operator" / "<=" { return "lte"; } / "<" { return "lt"; } -quotedString "quote" = "\"" chars:[^"\r\n]* "\"" { return chars.join(""); } - -alphanumeric "word" - = chars:[^ "\t\n\r]+ { - return chars.join("").trim().split(",").filter(Boolean); +quotedString "quote" + = start:[^ ,"\t\n\r]* "\"" inner:[^"\r\n]* "\"" end:[^ ,\t\n\r]* { + return [...start, '"', ...inner, '"', ...end].join(""); } +alphanumeric "word" = chars:[^ ,\t\n\r]+ { return chars.join("").trim(); } + logicalAnd = _ { return "and"; } _ "whitespace" = [ \t\r\n]* diff --git a/src/libs/SearchParser/searchParser.js b/src/libs/SearchParser/searchParser.js index 4c036f1d2c91..1e8d12f16a32 100644 --- a/src/libs/SearchParser/searchParser.js +++ b/src/libs/SearchParser/searchParser.js @@ -200,17 +200,19 @@ function peg$parse(input, options) { var peg$c17 = "sortBy"; var peg$c18 = "sortOrder"; var peg$c19 = "policyID"; - var peg$c20 = "!="; - var peg$c21 = ">="; - var peg$c22 = ">"; - var peg$c23 = "<="; - var peg$c24 = "<"; - var peg$c25 = "\""; + var peg$c20 = ","; + var peg$c21 = "!="; + var peg$c22 = ">="; + var peg$c23 = ">"; + var peg$c24 = "<="; + var peg$c25 = "<"; + var peg$c26 = "\""; var peg$r0 = /^[:=]/; - var peg$r1 = /^[^"\r\n]/; - var peg$r2 = /^[^ "\t\n\r]/; - var peg$r3 = /^[ \t\r\n]/; + var peg$r1 = /^[^ ,"\t\n\r]/; + var peg$r2 = /^[^"\r\n]/; + var peg$r3 = /^[^ ,\t\n\r]/; + var peg$r4 = /^[ \t\r\n]/; var peg$e0 = peg$otherExpectation("key"); var peg$e1 = peg$literalExpectation("date", false); @@ -234,20 +236,22 @@ function peg$parse(input, options) { var peg$e19 = peg$literalExpectation("sortBy", false); var peg$e20 = peg$literalExpectation("sortOrder", false); var peg$e21 = peg$literalExpectation("policyID", false); - var peg$e22 = peg$otherExpectation("operator"); - var peg$e23 = peg$classExpectation([":", "="], false, false); - var peg$e24 = peg$literalExpectation("!=", false); - var peg$e25 = peg$literalExpectation(">=", false); - var peg$e26 = peg$literalExpectation(">", false); - var peg$e27 = peg$literalExpectation("<=", false); - var peg$e28 = peg$literalExpectation("<", false); - var peg$e29 = peg$otherExpectation("quote"); - var peg$e30 = peg$literalExpectation("\"", false); - var peg$e31 = peg$classExpectation(["\"", "\r", "\n"], true, false); - var peg$e32 = peg$otherExpectation("word"); - var peg$e33 = peg$classExpectation([" ", "\"", "\t", "\n", "\r"], true, false); - var peg$e34 = peg$otherExpectation("whitespace"); - var peg$e35 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false); + var peg$e22 = peg$literalExpectation(",", false); + var peg$e23 = peg$otherExpectation("operator"); + var peg$e24 = peg$classExpectation([":", "="], false, false); + var peg$e25 = peg$literalExpectation("!=", false); + var peg$e26 = peg$literalExpectation(">=", false); + var peg$e27 = peg$literalExpectation(">", false); + var peg$e28 = peg$literalExpectation("<=", false); + var peg$e29 = peg$literalExpectation("<", false); + var peg$e30 = peg$otherExpectation("quote"); + var peg$e31 = peg$classExpectation([" ", ",", "\"", "\t", "\n", "\r"], true, false); + var peg$e32 = peg$literalExpectation("\"", false); + var peg$e33 = peg$classExpectation(["\"", "\r", "\n"], true, false); + var peg$e34 = peg$classExpectation([" ", ",", "\t", "\n", "\r"], true, false); + var peg$e35 = peg$otherExpectation("word"); + var peg$e36 = peg$otherExpectation("whitespace"); + var peg$e37 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false); var peg$f0 = function(filters) { return applyDefaults(filters); }; var peg$f1 = function(head, tail) { @@ -287,9 +291,14 @@ function peg$parse(input, options) { return buildFilter(op, field, values); }; var peg$f5 = function(parts) { - const value = parts.flat(); + const value = parts.flat().map((word) => { + if (word.startsWith('"') && word.endsWith('"') && word.length >= 2) { + return word.slice(1,-1); + } + return word; + }); if (value.length > 1) { - return value; + return value.filter((word) => word.length > 0); } return value[0]; }; @@ -299,10 +308,10 @@ function peg$parse(input, options) { var peg$f9 = function() { return "gt"; }; var peg$f10 = function() { return "lte"; }; var peg$f11 = function() { return "lt"; }; - var peg$f12 = function(chars) { return chars.join(""); }; - var peg$f13 = function(chars) { - return chars.join("").trim().split(",").filter(Boolean); + var peg$f12 = function(start, inner, end) { + return [...start, '"', ...inner, '"', ...end].join(""); }; + var peg$f13 = function(chars) { return chars.join("").trim(); }; var peg$f14 = function() { return "and"; }; var peg$currPos = options.peg$currPos | 0; var peg$savedPos = peg$currPos; @@ -840,24 +849,45 @@ function peg$parse(input, options) { } function peg$parseidentifier() { - var s0, s1, s2; + var s0, s1, s2, s3, s4; s0 = peg$currPos; - s1 = []; - s2 = peg$parsequotedString(); - if (s2 === peg$FAILED) { - s2 = peg$parsealphanumeric(); + s1 = peg$currPos; + s2 = []; + s3 = peg$parsequotedString(); + if (s3 === peg$FAILED) { + s3 = peg$parsealphanumeric(); } - if (s2 !== peg$FAILED) { - while (s2 !== peg$FAILED) { - s1.push(s2); - s2 = peg$parsequotedString(); - if (s2 === peg$FAILED) { - s2 = peg$parsealphanumeric(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 44) { + s4 = peg$c20; + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e22); } + } + if (s4 !== peg$FAILED) { + s4 = peg$parsequotedString(); + if (s4 === peg$FAILED) { + s4 = peg$parsealphanumeric(); + } + if (s4 === peg$FAILED) { + peg$currPos = s3; + s3 = peg$FAILED; + } else { + s3 = s4; } + } else { + s3 = s4; } - } else { + } + if (s2.length < 1) { + peg$currPos = s1; s1 = peg$FAILED; + } else { + s1 = s2; } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -878,7 +908,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e23); } + if (peg$silentFails === 0) { peg$fail(peg$e24); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -887,12 +917,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c20) { - s1 = peg$c20; + if (input.substr(peg$currPos, 2) === peg$c21) { + s1 = peg$c21; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e24); } + if (peg$silentFails === 0) { peg$fail(peg$e25); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -901,12 +931,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c21) { - s1 = peg$c21; + if (input.substr(peg$currPos, 2) === peg$c22) { + s1 = peg$c22; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e25); } + if (peg$silentFails === 0) { peg$fail(peg$e26); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -916,11 +946,11 @@ function peg$parse(input, options) { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 62) { - s1 = peg$c22; + s1 = peg$c23; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e26); } + if (peg$silentFails === 0) { peg$fail(peg$e27); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -929,12 +959,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c23) { - s1 = peg$c23; + if (input.substr(peg$currPos, 2) === peg$c24) { + s1 = peg$c24; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e27); } + if (peg$silentFails === 0) { peg$fail(peg$e28); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -944,11 +974,11 @@ function peg$parse(input, options) { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 60) { - s1 = peg$c24; + s1 = peg$c25; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e28); } + if (peg$silentFails === 0) { peg$fail(peg$e29); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -963,53 +993,89 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e22); } + if (peg$silentFails === 0) { peg$fail(peg$e23); } } return s0; } function peg$parsequotedString() { - var s0, s1, s2, s3; + var s0, s1, s2, s3, s4, s5, s6; peg$silentFails++; s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c25; + s1 = []; + s2 = input.charAt(peg$currPos); + if (peg$r1.test(s2)) { peg$currPos++; } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e30); } + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e31); } } - if (s1 !== peg$FAILED) { - s2 = []; - s3 = input.charAt(peg$currPos); - if (peg$r1.test(s3)) { + while (s2 !== peg$FAILED) { + s1.push(s2); + s2 = input.charAt(peg$currPos); + if (peg$r1.test(s2)) { peg$currPos++; } else { - s3 = peg$FAILED; + s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e31); } } - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = input.charAt(peg$currPos); - if (peg$r1.test(s3)) { + } + if (input.charCodeAt(peg$currPos) === 34) { + s2 = peg$c26; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e32); } + } + if (s2 !== peg$FAILED) { + s3 = []; + s4 = input.charAt(peg$currPos); + if (peg$r2.test(s4)) { + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e33); } + } + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = input.charAt(peg$currPos); + if (peg$r2.test(s4)) { peg$currPos++; } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e31); } + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e33); } } } if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c25; + s4 = peg$c26; peg$currPos++; } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e30); } + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e32); } } - if (s3 !== peg$FAILED) { + if (s4 !== peg$FAILED) { + s5 = []; + s6 = input.charAt(peg$currPos); + if (peg$r3.test(s6)) { + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e34); } + } + while (s6 !== peg$FAILED) { + s5.push(s6); + s6 = input.charAt(peg$currPos); + if (peg$r3.test(s6)) { + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e34); } + } + } peg$savedPos = s0; - s0 = peg$f12(s2); + s0 = peg$f12(s1, s3, s5); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1021,7 +1087,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e29); } + if (peg$silentFails === 0) { peg$fail(peg$e30); } } return s0; @@ -1034,21 +1100,21 @@ function peg$parse(input, options) { s0 = peg$currPos; s1 = []; s2 = input.charAt(peg$currPos); - if (peg$r2.test(s2)) { + if (peg$r3.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e33); } + if (peg$silentFails === 0) { peg$fail(peg$e34); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); s2 = input.charAt(peg$currPos); - if (peg$r2.test(s2)) { + if (peg$r3.test(s2)) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e33); } + if (peg$silentFails === 0) { peg$fail(peg$e34); } } } } else { @@ -1062,7 +1128,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e32); } + if (peg$silentFails === 0) { peg$fail(peg$e35); } } return s0; @@ -1086,25 +1152,25 @@ function peg$parse(input, options) { peg$silentFails++; s0 = []; s1 = input.charAt(peg$currPos); - if (peg$r3.test(s1)) { + if (peg$r4.test(s1)) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e35); } + if (peg$silentFails === 0) { peg$fail(peg$e37); } } while (s1 !== peg$FAILED) { s0.push(s1); s1 = input.charAt(peg$currPos); - if (peg$r3.test(s1)) { + if (peg$r4.test(s1)) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e35); } + if (peg$silentFails === 0) { peg$fail(peg$e37); } } } peg$silentFails--; s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e34); } + if (peg$silentFails === 0) { peg$fail(peg$e36); } return s0; } diff --git a/src/libs/SearchParser/searchParser.peggy b/src/libs/SearchParser/searchParser.peggy index 6429719d9dbd..7d5815d41459 100644 --- a/src/libs/SearchParser/searchParser.peggy +++ b/src/libs/SearchParser/searchParser.peggy @@ -114,10 +114,15 @@ defaultKey "default key" = @("type" / "status" / "sortBy" / "sortOrder" / "policyID") identifier - = parts:(quotedString / alphanumeric)+ { - const value = parts.flat(); + = parts:(quotedString / alphanumeric)|1.., ","| { + const value = parts.flat().map((word) => { + if (word.startsWith('"') && word.endsWith('"') && word.length >= 2) { + return word.slice(1,-1); + } + return word; + }); if (value.length > 1) { - return value; + return value.filter((word) => word.length > 0); } return value[0]; }