dfilter: Fix expressions with bytes as a character constant

Before:
  Filter: frame[1] == 'a'
  dftest: "'a'" is not a valid byte string.

After:
  Filter: frame[1] == 'a'

  Constants:
  00000 PUT_FVALUE	61 <FT_BYTES> -> reg#2

  Instructions:
  00000 READ_TREE		frame -> reg#0
  00001 IF-FALSE-GOTO	4
  00002 MK_RANGE		reg#0[1:1] -> reg#1
  00003 ANY_EQ		reg#1 == reg#2
  00004 RETURN

Fixes 4d2f469212.
This commit is contained in:
João Valverde 2021-10-31 20:08:39 +00:00
parent 552ee4c445
commit 15051c0671
2 changed files with 10 additions and 1 deletions

View File

@ -569,7 +569,7 @@ dfilter_fvalue_from_charconst_string(dfwork_t *dfw, ftenum_t ftype, stnode_t *st
fvalue_t *fvalue;
const char *s = stnode_data(st);
fvalue = fvalue_from_unparsed(ftype, s, allow_partial_value,
fvalue = fvalue_from_unparsed(FT_CHAR, s, allow_partial_value,
dfw->error_message == NULL ? &dfw->error_message : NULL);
if (fvalue == NULL)
THROW(TypeError);

View File

@ -90,3 +90,12 @@ class case_syntax(unittest.TestCase):
def test_deprecated_2(self, checkDFilterSucceed):
dfilter = "bootp"
checkDFilterSucceed(dfilter, "Deprecated tokens: \"bootp\"")
def test_charconst_1(self, checkDFilterCount):
# Bytes as a character constant.
dfilter = "frame contains 'H'"
checkDFilterCount(dfilter, 1)
def test_charconst_2(self, checkDFilterCount):
dfilter = "frame[54] == 'H'"
checkDFilterCount(dfilter, 1)