diff --git a/build/ConditionParser.js b/build/ConditionParser.js index 7ad0a0b..9b06dfb 100644 --- a/build/ConditionParser.js +++ b/build/ConditionParser.js @@ -203,52 +203,45 @@ function peg$parse(input, options) { var peg$c0 = "("; var peg$c1 = ")"; var peg$c2 = "and"; - var peg$c3 = "AND"; - var peg$c4 = "&&"; - var peg$c5 = "not"; - var peg$c6 = "NOT"; - var peg$c7 = "Not"; - var peg$c8 = "!"; - var peg$c9 = "or"; - var peg$c10 = "OR"; - var peg$c11 = "||"; - var peg$c12 = "=="; - var peg$c13 = "="; - var peg$c14 = "Equals"; - var peg$c15 = "Is"; - var peg$c16 = "is"; - var peg$c17 = "!="; - var peg$c18 = "NotEquals"; - var peg$c19 = "notequals"; - var peg$c20 = "IsNot"; - var peg$c21 = "isnot"; - var peg$c22 = ":="; - var peg$c23 = "EqualsCaseInsensitive"; - var peg$c24 = ">"; - var peg$c25 = "GreaterThan"; - var peg$c26 = ">="; - var peg$c27 = "GreaterThanOrEquals"; - var peg$c28 = "<"; - var peg$c29 = "LesserThan"; - var peg$c30 = "<="; - var peg$c31 = "LesserThanOrEquals"; - var peg$c32 = "~~"; - var peg$c33 = "JavaRegex"; - var peg$c34 = "~"; - var peg$c35 = "Matches"; - var peg$c36 = "Like"; - var peg$c37 = "~/"; - var peg$c38 = "MatchesPath"; - var peg$c39 = "LikePath"; - var peg$c40 = "=|"; - var peg$c41 = "StartsWith"; - var peg$c42 = "."; - var peg$c43 = "-"; - var peg$c44 = "0"; - var peg$c45 = "\""; - var peg$c46 = "null"; - var peg$c47 = "false"; - var peg$c48 = "true"; + var peg$c3 = "&&"; + var peg$c4 = "not"; + var peg$c5 = "!"; + var peg$c6 = "or"; + var peg$c7 = "||"; + var peg$c8 = "=="; + var peg$c9 = "="; + var peg$c10 = "equals"; + var peg$c11 = "is"; + var peg$c12 = "!="; + var peg$c13 = "notequals"; + var peg$c14 = "isnot"; + var peg$c15 = ":="; + var peg$c16 = "equalscaseinsensitive"; + var peg$c17 = ">"; + var peg$c18 = "greaterthan"; + var peg$c19 = ">="; + var peg$c20 = "greaterthanorequals"; + var peg$c21 = "<"; + var peg$c22 = "lesserthan"; + var peg$c23 = "<="; + var peg$c24 = "lesserthanorequals"; + var peg$c25 = "~~"; + var peg$c26 = "javaregex"; + var peg$c27 = "~"; + var peg$c28 = "matches"; + var peg$c29 = "like"; + var peg$c30 = "~/"; + var peg$c31 = "matchespath"; + var peg$c32 = "likepath"; + var peg$c33 = "=|"; + var peg$c34 = "startswith"; + var peg$c35 = "."; + var peg$c36 = "-"; + var peg$c37 = "0"; + var peg$c38 = "\""; + var peg$c39 = "null"; + var peg$c40 = "false"; + var peg$c41 = "true"; var peg$r0 = /^[0-9]/; var peg$r1 = /^[1-9]/; @@ -259,59 +252,52 @@ function peg$parse(input, options) { var peg$e0 = peg$literalExpectation("(", false); var peg$e1 = peg$literalExpectation(")", false); - var peg$e2 = peg$literalExpectation("and", false); - var peg$e3 = peg$literalExpectation("AND", false); - var peg$e4 = peg$literalExpectation("&&", false); - var peg$e5 = peg$literalExpectation("not", false); - var peg$e6 = peg$literalExpectation("NOT", false); - var peg$e7 = peg$literalExpectation("Not", false); - var peg$e8 = peg$literalExpectation("!", false); - var peg$e9 = peg$literalExpectation("or", false); - var peg$e10 = peg$literalExpectation("OR", false); - var peg$e11 = peg$literalExpectation("||", false); - var peg$e12 = peg$literalExpectation("==", false); - var peg$e13 = peg$literalExpectation("=", false); - var peg$e14 = peg$literalExpectation("Equals", false); - var peg$e15 = peg$literalExpectation("Is", false); - var peg$e16 = peg$literalExpectation("is", false); - var peg$e17 = peg$literalExpectation("!=", false); - var peg$e18 = peg$literalExpectation("NotEquals", false); - var peg$e19 = peg$literalExpectation("notequals", false); - var peg$e20 = peg$literalExpectation("IsNot", false); - var peg$e21 = peg$literalExpectation("isnot", false); - var peg$e22 = peg$literalExpectation(":=", false); - var peg$e23 = peg$literalExpectation("EqualsCaseInsensitive", false); - var peg$e24 = peg$literalExpectation(">", false); - var peg$e25 = peg$literalExpectation("GreaterThan", false); - var peg$e26 = peg$literalExpectation(">=", false); - var peg$e27 = peg$literalExpectation("GreaterThanOrEquals", false); - var peg$e28 = peg$literalExpectation("<", false); - var peg$e29 = peg$literalExpectation("LesserThan", false); - var peg$e30 = peg$literalExpectation("<=", false); - var peg$e31 = peg$literalExpectation("LesserThanOrEquals", false); - var peg$e32 = peg$literalExpectation("~~", false); - var peg$e33 = peg$literalExpectation("JavaRegex", false); - var peg$e34 = peg$literalExpectation("~", false); - var peg$e35 = peg$literalExpectation("Matches", false); - var peg$e36 = peg$literalExpectation("Like", false); - var peg$e37 = peg$literalExpectation("~/", false); - var peg$e38 = peg$literalExpectation("MatchesPath", false); - var peg$e39 = peg$literalExpectation("LikePath", false); - var peg$e40 = peg$literalExpectation("=|", false); - var peg$e41 = peg$literalExpectation("StartsWith", false); - var peg$e42 = peg$literalExpectation(".", false); - var peg$e43 = peg$literalExpectation("-", false); - var peg$e44 = peg$literalExpectation("0", false); - var peg$e45 = peg$classExpectation([["0", "9"]], false, false); - var peg$e46 = peg$classExpectation([["1", "9"]], false, false); - var peg$e47 = peg$classExpectation([["a", "z"], ["A", "Z"]], false, false); - var peg$e48 = peg$classExpectation(["-", ["a", "z"], ["A", "Z"], ["0", "9"], "_", "."], false, false); - var peg$e49 = peg$literalExpectation("\"", false); - var peg$e50 = peg$classExpectation(["\""], true, false); - var peg$e51 = peg$literalExpectation("null", false); - var peg$e52 = peg$literalExpectation("false", false); - var peg$e53 = peg$literalExpectation("true", false); - var peg$e54 = peg$classExpectation([" ", "\t", "\n"], false, false); + var peg$e2 = peg$literalExpectation("and", true); + var peg$e3 = peg$literalExpectation("&&", false); + var peg$e4 = peg$literalExpectation("not", true); + var peg$e5 = peg$literalExpectation("!", false); + var peg$e6 = peg$literalExpectation("or", true); + var peg$e7 = peg$literalExpectation("||", false); + var peg$e8 = peg$literalExpectation("==", false); + var peg$e9 = peg$literalExpectation("=", false); + var peg$e10 = peg$literalExpectation("Equals", true); + var peg$e11 = peg$literalExpectation("Is", true); + var peg$e12 = peg$literalExpectation("!=", false); + var peg$e13 = peg$literalExpectation("NotEquals", true); + var peg$e14 = peg$literalExpectation("IsNot", true); + var peg$e15 = peg$literalExpectation(":=", false); + var peg$e16 = peg$literalExpectation("EqualsCaseInsensitive", true); + var peg$e17 = peg$literalExpectation(">", false); + var peg$e18 = peg$literalExpectation("GreaterThan", true); + var peg$e19 = peg$literalExpectation(">=", false); + var peg$e20 = peg$literalExpectation("GreaterThanOrEquals", true); + var peg$e21 = peg$literalExpectation("<", false); + var peg$e22 = peg$literalExpectation("LesserThan", true); + var peg$e23 = peg$literalExpectation("<=", false); + var peg$e24 = peg$literalExpectation("LesserThanOrEquals", true); + var peg$e25 = peg$literalExpectation("~~", false); + var peg$e26 = peg$literalExpectation("JavaRegex", true); + var peg$e27 = peg$literalExpectation("~", false); + var peg$e28 = peg$literalExpectation("Matches", true); + var peg$e29 = peg$literalExpectation("Like", true); + var peg$e30 = peg$literalExpectation("~/", false); + var peg$e31 = peg$literalExpectation("MatchesPath", true); + var peg$e32 = peg$literalExpectation("LikePath", true); + var peg$e33 = peg$literalExpectation("=|", false); + var peg$e34 = peg$literalExpectation("StartsWith", true); + var peg$e35 = peg$literalExpectation(".", false); + var peg$e36 = peg$literalExpectation("-", false); + var peg$e37 = peg$literalExpectation("0", false); + var peg$e38 = peg$classExpectation([["0", "9"]], false, false); + var peg$e39 = peg$classExpectation([["1", "9"]], false, false); + var peg$e40 = peg$classExpectation([["a", "z"], ["A", "Z"]], false, false); + var peg$e41 = peg$classExpectation(["-", ["a", "z"], ["A", "Z"], ["0", "9"], "_", "."], false, false); + var peg$e42 = peg$literalExpectation("\"", false); + var peg$e43 = peg$classExpectation(["\""], true, false); + var peg$e44 = peg$literalExpectation("null", false); + var peg$e45 = peg$literalExpectation("false", false); + var peg$e46 = peg$literalExpectation("true", false); + var peg$e47 = peg$classExpectation([" ", "\t", "\n"], false, false); var peg$f0 = function(left, op1, right) { return {operator:op1, operands:[left, right] } }; var peg$f1 = function(left, op1, right) { return {operator:op1, operands:[left,right]} }; @@ -927,30 +913,21 @@ function peg$parse(input, options) { function peg$parseop_and() { var s0; - if (input.substr(peg$currPos, 3) === peg$c2) { - s0 = peg$c2; + if (input.substr(peg$currPos, 3).toLowerCase() === peg$c2) { + s0 = input.substr(peg$currPos, 3); peg$currPos += 3; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e2); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 3) === peg$c3) { + if (input.substr(peg$currPos, 2) === peg$c3) { s0 = peg$c3; - peg$currPos += 3; + peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e3); } } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c4) { - s0 = peg$c4; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e4); } - } - } } return s0; @@ -959,38 +936,20 @@ function peg$parse(input, options) { function peg$parseop_not() { var s0; - if (input.substr(peg$currPos, 3) === peg$c5) { - s0 = peg$c5; + if (input.substr(peg$currPos, 3).toLowerCase() === peg$c4) { + s0 = input.substr(peg$currPos, 3); peg$currPos += 3; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e5); } + if (peg$silentFails === 0) { peg$fail(peg$e4); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 3) === peg$c6) { - s0 = peg$c6; - peg$currPos += 3; + if (input.charCodeAt(peg$currPos) === 33) { + s0 = peg$c5; + peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 3) === peg$c7) { - s0 = peg$c7; - peg$currPos += 3; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e7); } - } - if (s0 === peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 33) { - s0 = peg$c8; - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e8); } - } - } + if (peg$silentFails === 0) { peg$fail(peg$e5); } } } @@ -1000,29 +959,20 @@ function peg$parse(input, options) { function peg$parseop_or() { var s0; - if (input.substr(peg$currPos, 2) === peg$c9) { - s0 = peg$c9; + if (input.substr(peg$currPos, 2).toLowerCase() === peg$c6) { + s0 = input.substr(peg$currPos, 2); peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e9); } + if (peg$silentFails === 0) { peg$fail(peg$e6); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c10) { - s0 = peg$c10; + if (input.substr(peg$currPos, 2) === peg$c7) { + s0 = peg$c7; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e10); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c11) { - s0 = peg$c11; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e11); } - } + if (peg$silentFails === 0) { peg$fail(peg$e7); } } } @@ -1136,45 +1086,36 @@ function peg$parse(input, options) { function peg$parseop_equals() { var s0; - if (input.substr(peg$currPos, 2) === peg$c12) { - s0 = peg$c12; + if (input.substr(peg$currPos, 2) === peg$c8) { + s0 = peg$c8; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } + if (peg$silentFails === 0) { peg$fail(peg$e8); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 61) { - s0 = peg$c13; + s0 = peg$c9; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e13); } + if (peg$silentFails === 0) { peg$fail(peg$e9); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c14) { - s0 = peg$c14; + if (input.substr(peg$currPos, 6).toLowerCase() === peg$c10) { + s0 = input.substr(peg$currPos, 6); peg$currPos += 6; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e14); } + if (peg$silentFails === 0) { peg$fail(peg$e10); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c15) { - s0 = peg$c15; + if (input.substr(peg$currPos, 2).toLowerCase() === peg$c11) { + s0 = input.substr(peg$currPos, 2); peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e15); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c16) { - s0 = peg$c16; - peg$currPos += 2; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e16); } - } + if (peg$silentFails === 0) { peg$fail(peg$e11); } } } } @@ -1186,46 +1127,28 @@ function peg$parse(input, options) { function peg$parseop_notequals() { var s0; - if (input.substr(peg$currPos, 2) === peg$c17) { - s0 = peg$c17; + if (input.substr(peg$currPos, 2) === peg$c12) { + s0 = peg$c12; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e17); } + if (peg$silentFails === 0) { peg$fail(peg$e12); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 9) === peg$c18) { - s0 = peg$c18; + if (input.substr(peg$currPos, 9).toLowerCase() === peg$c13) { + s0 = input.substr(peg$currPos, 9); peg$currPos += 9; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e18); } + if (peg$silentFails === 0) { peg$fail(peg$e13); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 9) === peg$c19) { - s0 = peg$c19; - peg$currPos += 9; + if (input.substr(peg$currPos, 5).toLowerCase() === peg$c14) { + s0 = input.substr(peg$currPos, 5); + peg$currPos += 5; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e19); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 5) === peg$c20) { - s0 = peg$c20; - peg$currPos += 5; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e20); } - } - if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 5) === peg$c21) { - s0 = peg$c21; - peg$currPos += 5; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e21); } - } - } + if (peg$silentFails === 0) { peg$fail(peg$e14); } } } } @@ -1236,20 +1159,20 @@ function peg$parse(input, options) { function peg$parseop_equalsnocase() { var s0; - if (input.substr(peg$currPos, 2) === peg$c22) { - s0 = peg$c22; + if (input.substr(peg$currPos, 2) === peg$c15) { + s0 = peg$c15; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e22); } + if (peg$silentFails === 0) { peg$fail(peg$e15); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 21) === peg$c23) { - s0 = peg$c23; + if (input.substr(peg$currPos, 21).toLowerCase() === peg$c16) { + s0 = input.substr(peg$currPos, 21); peg$currPos += 21; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e23); } + if (peg$silentFails === 0) { peg$fail(peg$e16); } } } @@ -1260,19 +1183,19 @@ function peg$parse(input, options) { var s0; if (input.charCodeAt(peg$currPos) === 62) { - s0 = peg$c24; + s0 = peg$c17; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e24); } + if (peg$silentFails === 0) { peg$fail(peg$e17); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 11) === peg$c25) { - s0 = peg$c25; + if (input.substr(peg$currPos, 11).toLowerCase() === peg$c18) { + s0 = input.substr(peg$currPos, 11); peg$currPos += 11; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e25); } + if (peg$silentFails === 0) { peg$fail(peg$e18); } } } @@ -1282,20 +1205,20 @@ function peg$parse(input, options) { function peg$parseop_greatereq() { var s0; - if (input.substr(peg$currPos, 2) === peg$c26) { - s0 = peg$c26; + if (input.substr(peg$currPos, 2) === peg$c19) { + s0 = peg$c19; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e26); } + if (peg$silentFails === 0) { peg$fail(peg$e19); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 19) === peg$c27) { - s0 = peg$c27; + if (input.substr(peg$currPos, 19).toLowerCase() === peg$c20) { + s0 = input.substr(peg$currPos, 19); peg$currPos += 19; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e27); } + if (peg$silentFails === 0) { peg$fail(peg$e20); } } } @@ -1306,19 +1229,19 @@ function peg$parse(input, options) { var s0; if (input.charCodeAt(peg$currPos) === 60) { - s0 = peg$c28; + s0 = peg$c21; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e28); } + if (peg$silentFails === 0) { peg$fail(peg$e21); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 10) === peg$c29) { - s0 = peg$c29; + if (input.substr(peg$currPos, 10).toLowerCase() === peg$c22) { + s0 = input.substr(peg$currPos, 10); peg$currPos += 10; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e29); } + if (peg$silentFails === 0) { peg$fail(peg$e22); } } } @@ -1328,20 +1251,20 @@ function peg$parse(input, options) { function peg$parseop_lessereq() { var s0; - if (input.substr(peg$currPos, 2) === peg$c30) { - s0 = peg$c30; + if (input.substr(peg$currPos, 2) === peg$c23) { + s0 = peg$c23; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e30); } + if (peg$silentFails === 0) { peg$fail(peg$e23); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 18) === peg$c31) { - s0 = peg$c31; + if (input.substr(peg$currPos, 18).toLowerCase() === peg$c24) { + s0 = input.substr(peg$currPos, 18); peg$currPos += 18; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e31); } + if (peg$silentFails === 0) { peg$fail(peg$e24); } } } @@ -1351,20 +1274,20 @@ function peg$parse(input, options) { function peg$parseop_regexmatch() { var s0; - if (input.substr(peg$currPos, 2) === peg$c32) { - s0 = peg$c32; + if (input.substr(peg$currPos, 2) === peg$c25) { + s0 = peg$c25; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e32); } + if (peg$silentFails === 0) { peg$fail(peg$e25); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 9) === peg$c33) { - s0 = peg$c33; + if (input.substr(peg$currPos, 9).toLowerCase() === peg$c26) { + s0 = input.substr(peg$currPos, 9); peg$currPos += 9; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e33); } + if (peg$silentFails === 0) { peg$fail(peg$e26); } } } @@ -1375,27 +1298,27 @@ function peg$parse(input, options) { var s0; if (input.charCodeAt(peg$currPos) === 126) { - s0 = peg$c34; + s0 = peg$c27; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e34); } + if (peg$silentFails === 0) { peg$fail(peg$e27); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 7) === peg$c35) { - s0 = peg$c35; + if (input.substr(peg$currPos, 7).toLowerCase() === peg$c28) { + s0 = input.substr(peg$currPos, 7); peg$currPos += 7; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e35); } + if (peg$silentFails === 0) { peg$fail(peg$e28); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c36) { - s0 = peg$c36; + if (input.substr(peg$currPos, 4).toLowerCase() === peg$c29) { + s0 = input.substr(peg$currPos, 4); peg$currPos += 4; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e36); } + if (peg$silentFails === 0) { peg$fail(peg$e29); } } } } @@ -1406,28 +1329,28 @@ function peg$parse(input, options) { function peg$parseop_matchespath() { var s0; - if (input.substr(peg$currPos, 2) === peg$c37) { - s0 = peg$c37; + if (input.substr(peg$currPos, 2) === peg$c30) { + s0 = peg$c30; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e37); } + if (peg$silentFails === 0) { peg$fail(peg$e30); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 11) === peg$c38) { - s0 = peg$c38; + if (input.substr(peg$currPos, 11).toLowerCase() === peg$c31) { + s0 = input.substr(peg$currPos, 11); peg$currPos += 11; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e38); } + if (peg$silentFails === 0) { peg$fail(peg$e31); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c39) { - s0 = peg$c39; + if (input.substr(peg$currPos, 8).toLowerCase() === peg$c32) { + s0 = input.substr(peg$currPos, 8); peg$currPos += 8; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e39); } + if (peg$silentFails === 0) { peg$fail(peg$e32); } } } } @@ -1438,20 +1361,20 @@ function peg$parse(input, options) { function peg$parseop_startswith() { var s0; - if (input.substr(peg$currPos, 2) === peg$c40) { - s0 = peg$c40; + if (input.substr(peg$currPos, 2) === peg$c33) { + s0 = peg$c33; peg$currPos += 2; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e40); } + if (peg$silentFails === 0) { peg$fail(peg$e33); } } if (s0 === peg$FAILED) { - if (input.substr(peg$currPos, 10) === peg$c41) { - s0 = peg$c41; + if (input.substr(peg$currPos, 10).toLowerCase() === peg$c34) { + s0 = input.substr(peg$currPos, 10); peg$currPos += 10; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e41); } + if (peg$silentFails === 0) { peg$fail(peg$e34); } } } @@ -1463,11 +1386,11 @@ function peg$parse(input, options) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 46) { - s1 = peg$c42; + s1 = peg$c35; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e42); } + if (peg$silentFails === 0) { peg$fail(peg$e35); } } if (s1 !== peg$FAILED) { s2 = peg$parseDecimalIntegerLiteral(); @@ -1491,11 +1414,11 @@ function peg$parse(input, options) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { - s1 = peg$c43; + s1 = peg$c36; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e43); } + if (peg$silentFails === 0) { peg$fail(peg$e36); } } if (s1 === peg$FAILED) { s1 = null; @@ -1503,11 +1426,11 @@ function peg$parse(input, options) { s2 = peg$parseDecimalIntegerLiteral(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 46) { - s3 = peg$c42; + s3 = peg$c35; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e42); } + if (peg$silentFails === 0) { peg$fail(peg$e35); } } if (s3 !== peg$FAILED) { s4 = peg$currPos; @@ -1545,11 +1468,11 @@ function peg$parse(input, options) { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 46) { - s1 = peg$c42; + s1 = peg$c35; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e42); } + if (peg$silentFails === 0) { peg$fail(peg$e35); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; @@ -1583,11 +1506,11 @@ function peg$parse(input, options) { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { - s1 = peg$c43; + s1 = peg$c36; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e43); } + if (peg$silentFails === 0) { peg$fail(peg$e36); } } if (s1 === peg$FAILED) { s1 = null; @@ -1610,11 +1533,11 @@ function peg$parse(input, options) { var s0, s1, s2, s3; if (input.charCodeAt(peg$currPos) === 48) { - s0 = peg$c44; + s0 = peg$c37; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e44); } + if (peg$silentFails === 0) { peg$fail(peg$e37); } } if (s0 === peg$FAILED) { s0 = peg$currPos; @@ -1649,7 +1572,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e45); } + if (peg$silentFails === 0) { peg$fail(peg$e38); } } return s0; @@ -1663,7 +1586,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e46); } + if (peg$silentFails === 0) { peg$fail(peg$e39); } } return s0; @@ -1677,7 +1600,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e47); } + if (peg$silentFails === 0) { peg$fail(peg$e40); } } return s0; @@ -1695,7 +1618,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e48); } + if (peg$silentFails === 0) { peg$fail(peg$e41); } } while (s3 !== peg$FAILED) { s2.push(s3); @@ -1704,7 +1627,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e48); } + if (peg$silentFails === 0) { peg$fail(peg$e41); } } } peg$savedPos = s0; @@ -1722,11 +1645,11 @@ function peg$parse(input, options) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c45; + s1 = peg$c38; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e49); } + if (peg$silentFails === 0) { peg$fail(peg$e42); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1735,7 +1658,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e50); } + if (peg$silentFails === 0) { peg$fail(peg$e43); } } while (s3 !== peg$FAILED) { s2.push(s3); @@ -1744,15 +1667,15 @@ function peg$parse(input, options) { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e50); } + if (peg$silentFails === 0) { peg$fail(peg$e43); } } } if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c45; + s3 = peg$c38; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e49); } + if (peg$silentFails === 0) { peg$fail(peg$e42); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; @@ -1767,12 +1690,12 @@ function peg$parse(input, options) { } if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c46) { - s1 = peg$c46; + if (input.substr(peg$currPos, 4) === peg$c39) { + s1 = peg$c39; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e51); } + if (peg$silentFails === 0) { peg$fail(peg$e44); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -1781,12 +1704,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 5) === peg$c47) { - s1 = peg$c47; + if (input.substr(peg$currPos, 5) === peg$c40) { + s1 = peg$c40; peg$currPos += 5; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e52); } + if (peg$silentFails === 0) { peg$fail(peg$e45); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -1795,12 +1718,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c48) { - s1 = peg$c48; + if (input.substr(peg$currPos, 4) === peg$c41) { + s1 = peg$c41; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e53); } + if (peg$silentFails === 0) { peg$fail(peg$e46); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -1831,7 +1754,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e54); } + if (peg$silentFails === 0) { peg$fail(peg$e47); } } return s0; diff --git a/lib/peggy/Apigee-Condition.pegjs b/lib/peggy/Apigee-Condition.pegjs index da452fc..f10e9c1 100644 --- a/lib/peggy/Apigee-Condition.pegjs +++ b/lib/peggy/Apigee-Condition.pegjs @@ -2,7 +2,7 @@ // A peggy grammar for the Condition expressions used in Apigee. // // -// Copyright 2015 Apigee Corp, 2023 Google LLC. +// Copyright 2015 Apigee Corp, 2024 Google LLC. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -72,7 +72,6 @@ boolean_stmt2 factor = op_not ws* operand:factor { return {operator:"NOT", operands:[operand] } } / primary - primary = "(" ws* t1:token ws+ op1:operator ws+ v1:value ws* ")" { @@ -89,11 +88,11 @@ op_boolean = op_and {return "AND"; } / op_or {return "OR"; } -op_and = "and" / "AND" / "&&" +op_and = "and"i / "&&" -op_not = "not" / "NOT" / "Not" / "!" +op_not = "not"i / "!" -op_or = "or" / "OR" / "||" +op_or = "or"i / "||" // Ordering is important. For operators that share a common prefix, // list the longer, more specific operator, first. @@ -111,27 +110,27 @@ operator / op_matchespath {return "MatchesPath";} / op_matches {return "Matches";} -op_equals = "==" / "=" / "Equals" / "Is" / "is" +op_equals = "==" / "=" / "Equals"i / "Is"i -op_notequals = "!=" / "NotEquals" / "notequals" / "IsNot" / "isnot" +op_notequals = "!=" / "NotEquals"i / "IsNot"i -op_equalsnocase = ":=" / "EqualsCaseInsensitive" +op_equalsnocase = ":=" / "EqualsCaseInsensitive"i -op_greater = ">" / "GreaterThan" +op_greater = ">" / "GreaterThan"i -op_greatereq = ">=" / "GreaterThanOrEquals" +op_greatereq = ">=" / "GreaterThanOrEquals"i -op_lesser = "<" / "LesserThan" +op_lesser = "<" / "LesserThan"i -op_lessereq = "<=" / "LesserThanOrEquals" +op_lessereq = "<=" / "LesserThanOrEquals"i -op_regexmatch = "~~" / "JavaRegex" +op_regexmatch = "~~" / "JavaRegex"i -op_matches = "~" / "Matches" / "Like" +op_matches = "~" / "Matches"i / "Like"i -op_matchespath = "~/" / "MatchesPath" / "LikePath" +op_matchespath = "~/" / "MatchesPath"i / "LikePath"i -op_startswith = "=|" / "StartsWith" +op_startswith = "=|" / "StartsWith"i frac_string diff --git a/test/specs/ConditionParserTest.js b/test/specs/ConditionParserTest.js index 9b08f1b..6e57a32 100644 --- a/test/specs/ConditionParserTest.js +++ b/test/specs/ConditionParserTest.js @@ -1,5 +1,5 @@ /* - Copyright 2019-2023 Google LLC + Copyright 2019-2024 Google LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -72,13 +72,28 @@ describe("ConditionParser", function () { it("treats parenthesized and non-parenthesized atoms as equivalent", function () { const c1 = "!valid"; - const c2 = "!(valid)"; const result1 = parser.parse(c1); + const json1 = JSON.stringify(result1); + expect(json1).to.equal('{"operator":"NOT","operands":["valid"]}'); + const c2 = "!(valid)"; const result2 = parser.parse(c2); - expect(JSON.stringify(result1)).to.equal(JSON.stringify(result2)); - expect(JSON.stringify(result1)).to.equal( - '{"operator":"NOT","operands":["valid"]}' - ); + expect(json1).to.equal(JSON.stringify(result2)); + const c3 = "not valid"; + const result3 = parser.parse(c3); + expect(json1).to.equal(JSON.stringify(result3)); + }); + + it("treats NOT as case-insensitive", function () { + const c1 = "!(valid)"; + const result1 = parser.parse(c1); + const json1 = JSON.stringify(result1); + expect(json1).to.equal('{"operator":"NOT","operands":["valid"]}'); + const synonyms = ["not(valid)", "Not(valid)", "nOT(valid)"]; + for (let i = 0; i < synonyms.length; i++) { + const c2 = synonyms[i]; + const result2 = parser.parse(c2); + expect(json1).to.equal(JSON.stringify(result2)); + } }); it("parses negation of parenthesized compound expression", function () { @@ -156,6 +171,18 @@ describe("ConditionParser", function () { expect(result.operands[1].operands[0].operator).to.equal("Equals"); expect(result.operands[1].operands[1].operator).to.equal("Equals"); }); + + it("treats AND as case-insensitive", function () { + const c1 = '(proxy.pathsuffix ~ "/authorize") && (request.verb = "POST")'; + const result1 = parser.parse(c1); + const json1 = JSON.stringify(result1); + const variants = ["And", "AND", "and", "aNd", "anD", "ANd", "aND"]; + for (let i = 0; i < variants.length; i++) { + const c2 = c1.replace("&&", variants[i]); + const result2 = parser.parse(c2); + expect(json1).to.equal(JSON.stringify(result2)); + } + }); }); describe("Invalid Operators", function () { @@ -176,6 +203,19 @@ describe("ConditionParser", function () { expect(e.toString()).to.include("SyntaxError"); } }); + const validOperators = ["equals", "notquals", "isnot", "is"]; + validOperators.forEach((goodOp) => { + const badOp = goodOp + "a"; + it(`rejects ${badOp} as an operator`, function () { + const c1 = `request.formparam.grant_type ${badOp} "authorization_code"`; + try { + parser.parse(c1); + expect.fail(); + } catch (e) { + expect(e.toString()).to.include("SyntaxError"); + } + }); + }); }); describe("OR statements", function () { @@ -186,6 +226,18 @@ describe("ConditionParser", function () { const result2 = parser.parse(c2); expect(JSON.stringify(result1)).to.equal(JSON.stringify(result2)); }); + + it("treats OR as case-insensitive", function () { + const c1 = '(proxy.pathsuffix ~ "/authorize") || (request.verb = "POST")'; + const result1 = parser.parse(c1); + const json1 = JSON.stringify(result1); + const variants = ["Or", "or", "oR", "OR"]; + for (let i = 0; i < variants.length; i++) { + const c2 = c1.replace("||", variants[i]); + const result2 = parser.parse(c2); + expect(json1).to.equal(JSON.stringify(result2)); + } + }); }); describe("implicit parens", function () { @@ -442,13 +494,14 @@ describe("ConditionParser", function () { }); }); - describe("Operator translation", function () { + describe("Operators", function () { const cases = [ { expression: 'A := "valid"', longFormOperator: "EqualsCaseInsensitive" }, { expression: 'A = "valid"', longFormOperator: "Equals" }, + { expression: 'A == "valid"', longFormOperator: "Equals" }, { expression: 'A != "valid"', longFormOperator: "NotEquals" }, { expression: 'A ~~ "foobar[a-z]+"', longFormOperator: "JavaRegex" }, { expression: 'A ~/ "/foo/bar"', longFormOperator: "MatchesPath" }, @@ -468,6 +521,49 @@ describe("ConditionParser", function () { } }); }); + + const randomizeCapitalization = (s) => + s + .toLowerCase() + .split("") + .map((c) => (Math.random() < 0.5 ? c : c.toUpperCase())) + .join(""); + + const cases2 = [ + 'A EqualsCaseInsensitive "valid"', + 'A Equals "valid"', + 'A NotEquals "valid"', + 'A JavaRegex "foobar[a-z]+"', + 'A MatchesPath "/foo/bar"', + 'A StartsWith "something"', + "A GreaterThanOrEquals 20", + "A GreaterThan 20", + "A LesserThanOrEquals 20", + "A LesserThan 20" + ]; + + cases2.forEach((expression) => { + it(`verifies that ${ + expression.split(" ")[1] + } is treated case insensitively`, function () { + try { + const result1 = parser.parse(expression); + const json1 = JSON.stringify(result1); + const parts = expression.split(" "); + for (let i = 0; i < 3; i++) { + const expression2 = [ + parts[0], + randomizeCapitalization(parts[1]), + parts[2] + ].join(" "); + const result2 = parser.parse(expression2); + expect(json1).to.equal(JSON.stringify(result2)); + } + } catch (_e) { + expect.fail(_e); + } + }); + }); }); describe("Mismatch between Operator and operand", function () {