fix: keep negative index in jmespath unchanged when converting pytest files

This commit is contained in:
debugtalk
2022-03-22 17:00:09 +08:00
parent c57714bbfe
commit 35c385303d
3 changed files with 8 additions and 1 deletions

View File

@@ -58,9 +58,11 @@ def _convert_jmespath(raw: Text) -> Text:
raw_list = []
for item in raw.split("."):
if "-" in item:
if "-" in item and "[-" not in item:
# add quotes for field with separator
# e.g. headers.Content-Type => headers."Content-Type"
# also need to avoid replacing negative index in jmespath
# e.g. body.users[-1] => body.users[-1], keep unchanged
item = item.strip('"')
raw_list.append(f'"{item}"')
elif item.isdigit():