wireshark/epan/dfilter
João Valverde a975d478ba dfilter: Require double-quoted strings with "matches"
Matches is a special case that looks on the RHS and tries
to convert every unparsed value to a string, regardless
of the LHS type. This is not how types work in the display
filter. Require double-quotes to avoid ambiguity, because
matches doesn't follow normal Wireshark display filter
type rules. It doesn't need nor benefit from the flexibility
provided by unparsed strings in the syntax.

For matches the RHS is always a literal strings except
if the RHS is also a field name, then it complains of an
incompatible type. This is confusing. No type can be compatible
because no type rules are ever considered. Every unparsed value is
a text string except if it happens to coincide with a field
name it also requires double-quoting or it throws a syntax error,
just to be difficult. We could remove this odd quirk but requiring
double-quotes for regular expressions is a better, more elegant
fix.

Before:
  Filter: tcp matches "udp"

  Constants:
  00000 PUT_PCRE	udp -> reg#1

  Instructions:
  00000 READ_TREE		tcp -> reg#0
  00001 IF-FALSE-GOTO	3
  00002 ANY_MATCHES	reg#0 matches reg#1
  00003 RETURN

  Filter: tcp matches udp

  Constants:
  00000 PUT_PCRE	udp -> reg#1

  Instructions:
  00000 READ_TREE		tcp -> reg#0
  00001 IF-FALSE-GOTO	3
  00002 ANY_MATCHES	reg#0 matches reg#1
  00003 RETURN

  Filter: tcp matches udp.srcport
  dftest: tcp and udp.srcport are not of compatible types.

  Filter: tcp matches udp.srcportt

  Constants:
  00000 PUT_PCRE	udp.srcportt -> reg#1

  Instructions:
  00000 READ_TREE		tcp -> reg#0
  00001 IF-FALSE-GOTO	3
  00002 ANY_MATCHES	reg#0 matches reg#1
  00003 RETURN

After:
  Filter: tcp matches "udp"

  Constants:
  00000 PUT_PCRE	udp -> reg#1

  Instructions:
  00000 READ_TREE		tcp -> reg#0
  00001 IF-FALSE-GOTO	3
  00002 ANY_MATCHES	reg#0 matches reg#1
  00003 RETURN

  Filter: tcp matches udp
  dftest: "udp" was unexpected in this context.

  Filter: tcp matches udp.srcport
  dftest: "udp.srcport" was unexpected in this context.

  Filter: tcp matches udp.srcportt
  dftest: "udp.srcportt" was unexpected in this context.

The error message could still be improved.
2021-10-17 22:53:36 +00:00
..
.editorconfig dfilter: Improve grammar to parse ranges 2021-10-08 19:18:56 +01:00
CMakeLists.txt dfilter: Improve grammar to parse ranges 2021-10-08 19:18:56 +01:00
dfilter-int.h dfilter: Require double-quoted strings with "matches" 2021-10-17 22:53:36 +00:00
dfilter-macro.c dfilter: Fix handling of escaped quotes in macros 2021-05-28 10:36:41 +00:00
dfilter-macro.h
dfilter.c dfilter: Require double-quoted strings with "matches" 2021-10-17 22:53:36 +00:00
dfilter.h
dfunctions.c dfilter: Improve grammar to parse functions 2021-10-08 04:01:24 +00:00
dfunctions.h dfilter: Improve grammar to parse functions 2021-10-08 04:01:24 +00:00
dfvm.c Replace g_assert() with ws_assert() 2021-06-19 01:23:31 +00:00
dfvm.h dfilter, ftypes: get rid of FT_PCRE. 2021-03-21 03:27:44 -07:00
drange.c dfilter: Add range 'tostr' method 2021-10-01 16:04:37 +00:00
drange.h dfilter: Add range 'tostr' method 2021-10-01 16:04:37 +00:00
gencode.c Replace g_assert() with ws_assert() 2021-06-19 01:23:31 +00:00
gencode.h
grammar.lemon dfilter: Require double-quoted strings with "matches" 2021-10-17 22:53:36 +00:00
scanner.l dfilter: Fixup deprecated tokens initialization 2021-10-14 16:49:23 +01:00
semcheck.c dfilter: Require double-quoted strings with "matches" 2021-10-17 22:53:36 +00:00
semcheck.h dfilter: Clean up handling of "deprecated" tokens 2021-09-30 17:26:19 +01:00
sttype-function.c dfilter: Split tostr() into debug and pretty print 2021-10-11 21:55:45 +00:00
sttype-function.h
sttype-pointer.c dfilter: Split tostr() into debug and pretty print 2021-10-11 21:55:45 +00:00
sttype-range.c dfilter: Split tostr() into debug and pretty print 2021-10-11 21:55:45 +00:00
sttype-range.h dfilter: Replace node accessor macros with functions 2021-10-06 15:44:48 +00:00
sttype-set.c dfilter: Split tostr() into debug and pretty print 2021-10-11 21:55:45 +00:00
sttype-set.h dfilter: Use syntax tree node replacement semantics 2021-10-06 10:34:21 +00:00
sttype-string.c dfilter: Split tostr() into debug and pretty print 2021-10-11 21:55:45 +00:00
sttype-test.c dfilter: Split tostr() into debug and pretty print 2021-10-11 21:55:45 +00:00
sttype-test.h
syntax-tree.c dfilter: Require double-quoted strings with "matches" 2021-10-17 22:53:36 +00:00
syntax-tree.h dfilter: Remove unused function definition 2021-10-14 16:21:33 +01:00