diff --git a/confit/config.py b/confit/config.py index 648cdef..eb93022 100644 --- a/confit/config.py +++ b/confit/config.py @@ -145,7 +145,9 @@ def from_yaml_str(cls, s: str, resolve: bool = False, registry: Any = None) -> A class ConfitYamlLoader(yaml.SafeLoader): def construct_object(self, x, deep=False): if isinstance(x, yaml.ScalarNode): - return loads(self.buffer[x.start_mark.index : x.end_mark.index]) + if x.style == '"' or x.style == "'": + return loads(x.style + x.value + x.style) + return loads(x.value) return super().construct_object(x, deep) stream = StringIO(s) diff --git a/tests/test_config_instance.py b/tests/test_config_instance.py index 90dc6f0..ffd4038 100644 --- a/tests/test_config_instance.py +++ b/tests/test_config_instance.py @@ -685,3 +685,34 @@ def test_if_else_complex(): """ ).resolve(registry=registry) assert config["params"]["c"] == 12 + + +def test_very_long_yaml_config(): + config = Config.from_yaml_str( + """\ + a: {} + """.format( + "x" * 4200 + ) + ).resolve(registry=registry) + assert config == {"a": "x" * 4200} + + +def test_escaped_string(): + config = Config.from_yaml_str( + """ +test: + a: "1" +section: + num: 1 + escaped_num: "1" + real_ref: ${test.a} + escaped_broken_ref: "${test.a" + escaped_ref: "${test.a}" +""" + ).resolve(registry=registry) + assert config["section"]["num"] == 1 + assert config["section"]["escaped_num"] == "1" + assert config["section"]["real_ref"] == "1" + assert config["section"]["escaped_broken_ref"] == "${test.a" + assert config["section"]["escaped_ref"] == "${test.a}"