aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2022-04-04 19:58:35 +0100
committerA Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2022-04-04 20:28:55 +0000
commit330d40832848411da3c3d2646978e41240bf848b (patch)
tree60893827ea295ee9d4f975ce1f025e2f30991991 /test
parent34ad6bb47887fab144c8e2547dce58152111abb0 (diff)
dfilter: Allow arithmetic expressions without spaces
To allow an arithmetic expressions without spaces, such as "1+2", we cannot match the expression in other lexical rules using "+". Because of longest match this becomes the token LITERAL or UNPARSED with semantic value "1+2". The same goes for all the other arithmetic operators. So we need to remove [+-*/%] from "word chars" and add very specific patterns (that won't mistakenly match an arithmetic expression) for those literal or unparsed tokens we want to support using these characters. The plus was not a problem but right slash is used for CIDR, minus for mac address separator, etc. There are still some corner case. 11-22-33-44-55-66 is a mac address and not the arithmetic expression with six terms "eleven minus twenty two minus etc." (if we ever support more than two terms in the grammar, which we don't currently). We lift some patterns from the flex manual to match on IPv4 and IPv6 (ugly) and add MAC address. Other hypothetical literal lexical values using [+-*/%] are already supported enclosed in angle brackets but the cases of MAC/IPv4/IPv6 are are very common and moreover we need to do the utmost to not break backward compatibily here. Before: $ dftest "_ws.ftypes.int32 == 1+2" dftest: "1+2" is not a valid number. After: $ dftest "_ws.ftypes.int32 == 1+2" Filter: _ws.ftypes.int32 == 1+2 Instructions: 00000 READ_TREE _ws.ftypes.int32 -> reg#0 00001 IF_FALSE_GOTO 4 00002 ADD 1 <FT_INT32> + 2 <FT_INT32> -> reg#1 00003 ANY_EQ reg#0 == reg#1 00004 RETURN
Diffstat (limited to 'test')
-rw-r--r--test/suite_dfilter/group_syntax.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/test/suite_dfilter/group_syntax.py b/test/suite_dfilter/group_syntax.py
index 3dfa84141b..5b6768e748 100644
--- a/test/suite_dfilter/group_syntax.py
+++ b/test/suite_dfilter/group_syntax.py
@@ -198,6 +198,10 @@ class case_arithmetic(unittest.TestCase):
dfilter = "udp.dstport == 66 + 1"
checkDFilterCount(dfilter, 2)
+ def test_add_3(self, checkDFilterCount):
+ dfilter = "udp.dstport == 66+1"
+ checkDFilterCount(dfilter, 2)
+
def test_add_3(self, checkDFilterFail):
error = 'Constant arithmetic expression on the LHS is invalid'
dfilter = "2 + 3 == frame.number"