diff --git a/confit/utils/xjson.py b/confit/utils/xjson.py index 5a089cd..f49f36a 100644 --- a/confit/utils/xjson.py +++ b/confit/utils/xjson.py @@ -257,6 +257,7 @@ def __init__(self, value: str): self.value = value super().__init__(f"Malformed value: {value!r}") + def loads(s: str): """ Load an extended JSON string into a python object. @@ -266,15 +267,18 @@ def loads(s: str): return XJsonTransformer(s).transform(_json_parser.parse(s)) except Exception: # Detect malformed strings with unmatched quotes - if (s.startswith("'") and not s.endswith("'")) or (s.startswith('"') and not s.endswith('"')): + if (s.startswith("'") and not s.endswith("'")) or ( + s.startswith('"') and not s.endswith('"') + ): raise MalformedValueError(s) - + # Detect suspicious malformed patterns if any(char in s for char in ",{}[]") and not s.startswith(("'", '"')): raise MalformedValueError(s) - + return s - + + def dumps(o: Any): """ Dump a python object into an extended JSON string. diff --git a/tests/test_config_instance.py b/tests/test_config_instance.py index 00c261e..34b879c 100644 --- a/tests/test_config_instance.py +++ b/tests/test_config_instance.py @@ -691,6 +691,8 @@ def test_very_long_yaml_config(): config = Config.from_yaml_str( """\ a: {} - """.format("x" * 4200) + """.format( + "x" * 4200 + ) ) assert config == {"a": "x" * 4200}