diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a46cf878..46236a56 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,7 @@ ## 3.1.9 (2022-04-17) +- fix #1209: only convert jmespath path for some fields in white list - fix #1233: parse upload info with session variables - fix #1246: catch exceptions when getting socket address failed - fix #1247: catch exceptions caused by GA report failure diff --git a/httprunner/compat.py b/httprunner/compat.py index c14c9d1f..4b0c449a 100644 --- a/httprunner/compat.py +++ b/httprunner/compat.py @@ -58,11 +58,9 @@ def _convert_jmespath(raw: Text) -> Text: raw_list = [] for item in raw.split("."): - if "-" in item and "[-" not in item: - # add quotes for field with separator + if item.lower().startswith("content-") or item.lower() in ["user-agent"]: + # add quotes for some field in white list # 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(): @@ -257,12 +255,12 @@ def ensure_cli_args(args: List) -> List: """ # remove deprecated --failfast if "--failfast" in args: - logger.warning(f"remove deprecated argument: --failfast") + logger.warning("remove deprecated argument: --failfast") args.pop(args.index("--failfast")) # convert --report-file to --html if "--report-file" in args: - logger.warning(f"replace deprecated argument --report-file with --html") + logger.warning("replace deprecated argument --report-file with --html") index = args.index("--report-file") args[index] = "--html" args.append("--self-contained-html") @@ -270,7 +268,7 @@ def ensure_cli_args(args: List) -> List: # keep compatibility with --save-tests in v2 if "--save-tests" in args: logger.warning( - f"generate conftest.py keep compatibility with --save-tests in v2" + "generate conftest.py keep compatibility with --save-tests in v2" ) args.pop(args.index("--save-tests")) _generate_conftest_for_summary(args) diff --git a/tests/compat_test.py b/tests/compat_test.py index 987b1785..c56f9377 100644 --- a/tests/compat_test.py +++ b/tests/compat_test.py @@ -32,12 +32,14 @@ class TestCompat(unittest.TestCase): compat.convert_variables(None, "tests/data/a-b.c/1.yml") def test_convert_jmespath(self): - self.assertEqual(compat._convert_jmespath("content.abc"), "body.abc") self.assertEqual(compat._convert_jmespath("json.abc"), "body.abc") self.assertEqual( compat._convert_jmespath("headers.Content-Type"), 'headers."Content-Type"' ) + self.assertEqual( + compat._convert_jmespath('headers.User-Agent'), 'headers."User-Agent"' + ) self.assertEqual( compat._convert_jmespath('headers."Content-Type"'), 'headers."Content-Type"' ) @@ -49,6 +51,10 @@ class TestCompat(unittest.TestCase): compat._convert_jmespath("body.users[-1]"), "body.users[-1]", ) + self.assertEqual( + compat._convert_jmespath("body.result.WorkNode_-1"), + "body.result.WorkNode_-1", + ) with self.assertRaises(SystemExit): compat._convert_jmespath("2.buildings.0.building_id")