diff options
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | src/core/wee-eval.c | 17 | ||||
-rw-r--r-- | tests/unit/core/test-eval.cpp | 8 |
3 files changed, 21 insertions, 5 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index d2748de10..d002ce669 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -28,6 +28,7 @@ New features:: Bug fixes:: + * core: fix evaluation of condition when the left operand is an empty string * core: fix string evaluation with regex replacement when the string is empty * core: fix check of tags in lines (command /filter and hook_print) * core: fix clear of completion item in case of partial completion (issue #1162) diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index fffc07fb0..111277735 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -962,14 +962,21 @@ eval_expression_condition (const char *expr, for (comp = 0; comp < EVAL_NUM_COMPARISONS; comp++) { pos = eval_strstr_level (expr2, comparisons[comp], "(", ")", 0); - if (pos > expr2) + if (pos >= expr2) { - pos_end = pos - 1; - while ((pos_end > expr2) && (pos_end[0] == ' ')) + if (pos > expr2) { - pos_end--; + pos_end = pos - 1; + while ((pos_end > expr2) && (pos_end[0] == ' ')) + { + pos_end--; + } + sub_expr = string_strndup (expr2, pos_end + 1 - expr2); + } + else + { + sub_expr = strdup (""); } - sub_expr = string_strndup (expr2, pos_end + 1 - expr2); if (!sub_expr) goto end; pos += strlen (comparisons[comp]); diff --git a/tests/unit/core/test-eval.cpp b/tests/unit/core/test-eval.cpp index 742eb99bd..7e85a1811 100644 --- a/tests/unit/core/test-eval.cpp +++ b/tests/unit/core/test-eval.cpp @@ -96,6 +96,7 @@ TEST(CoreEval, EvalCondition) WEE_CHECK_EVAL("0", ""); WEE_CHECK_EVAL("0", "0"); WEE_CHECK_EVAL("0", "1 == 2"); + WEE_CHECK_EVAL("0", "==1"); WEE_CHECK_EVAL("0", "1 >= 2"); WEE_CHECK_EVAL("0", "2 <= 1"); WEE_CHECK_EVAL("0", "2 != 2"); @@ -115,6 +116,7 @@ TEST(CoreEval, EvalCondition) WEE_CHECK_EVAL("0", "0xA3 < 2"); WEE_CHECK_EVAL("0", "-0xA3 > 2"); WEE_CHECK_EVAL("0", "1 == 5 > 18"); + WEE_CHECK_EVAL("0", ">1"); WEE_CHECK_EVAL("0", "abc == def"); WEE_CHECK_EVAL("0", "()"); WEE_CHECK_EVAL("0", "(5 > 26)"); @@ -133,6 +135,7 @@ TEST(CoreEval, EvalCondition) WEE_CHECK_EVAL("0", "((0 || 1) && 1) && 0"); WEE_CHECK_EVAL("0", "abcd =~ (?-i)^ABC"); WEE_CHECK_EVAL("0", "abcd =~ \\(abcd\\)"); + WEE_CHECK_EVAL("0", "=~abcd"); WEE_CHECK_EVAL("0", "(abcd) =~ \\(\\(abcd\\)\\)"); WEE_CHECK_EVAL("0", "abcd =* abce"); WEE_CHECK_EVAL("0", "abcd =* a*e"); @@ -148,6 +151,7 @@ TEST(CoreEval, EvalCondition) WEE_CHECK_EVAL("1", "123"); WEE_CHECK_EVAL("1", "abc"); WEE_CHECK_EVAL("1", "2 == 2"); + WEE_CHECK_EVAL("1", "==0"); WEE_CHECK_EVAL("1", "2 >= 1"); WEE_CHECK_EVAL("1", "1 <= 2"); WEE_CHECK_EVAL("1", "1 != 2"); @@ -171,6 +175,7 @@ TEST(CoreEval, EvalCondition) WEE_CHECK_EVAL("1", "(26 > 5)"); WEE_CHECK_EVAL("1", "((26 > 5))"); WEE_CHECK_EVAL("1", "(5 < 26)"); + WEE_CHECK_EVAL("1", "<1"); WEE_CHECK_EVAL("1", "def > abc"); WEE_CHECK_EVAL("1", "1 && 1"); WEE_CHECK_EVAL("1", "abc && 1"); @@ -184,6 +189,9 @@ TEST(CoreEval, EvalCondition) WEE_CHECK_EVAL("1", "((0 || 1) && 1) && 1"); WEE_CHECK_EVAL("1", "abcd =~ ^ABC"); WEE_CHECK_EVAL("1", "abcd =~ (?-i)^abc"); + WEE_CHECK_EVAL("1", "abcd=~abc"); + WEE_CHECK_EVAL("1", "=~"); + WEE_CHECK_EVAL("1", "abc=~"); WEE_CHECK_EVAL("1", "(abcd) =~ (abcd)"); WEE_CHECK_EVAL("1", "(abcd) =~ \\(abcd\\)"); WEE_CHECK_EVAL("1", "((abcd)) =~ \\(\\(abcd\\)\\)"); |