Switch to ast.literal_eval for dict parsing

Due to  some test data in the BDD feature files includes Python raw strings and escape sequences that standard json.loads() cannot parse switching to safer Python literal evaluation
for converting string representations of dictionaries.
This commit is contained in:
Itz-Agasta
2026-01-21 11:33:17 +05:30
parent 9fa980bca2
commit e77a4c2f35
2 changed files with 5 additions and 3 deletions

View File

@@ -7,6 +7,7 @@
"""
Helper functions to compare expected values.
"""
import ast
import collections.abc
import json
import re
@@ -58,7 +59,8 @@ COMPARISON_FUNCS = {
None: lambda val, exp: str(val) == exp,
'i': lambda val, exp: str(val).lower() == exp.lower(),
'fm': lambda val, exp: re.fullmatch(exp, val) is not None,
'dict': lambda val, exp: val is None if exp == '-' else (val == json.loads('{' + exp + '}')),
'dict': lambda val, exp: (val is None if exp == '-'
else (val == ast.literal_eval('{' + exp + '}'))),
'in_box': within_box
}