Skip to content

Commit f5bae0d

Browse files
committed
Fix: add support for YAML config files over 4096 characters
1 parent ef01561 commit f5bae0d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

confit/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ def from_yaml_str(cls, s: str, resolve: bool = False, registry: Any = None) -> A
145145
class ConfitYamlLoader(yaml.SafeLoader):
146146
def construct_object(self, x, deep=False):
147147
if isinstance(x, yaml.ScalarNode):
148-
return loads(self.buffer[x.start_mark.index : x.end_mark.index])
148+
if x.style == '"' or x.style == "'":
149+
return loads(x.style + x.value + x.style)
150+
return loads(x.value)
149151
return super().construct_object(x, deep)
150152

151153
stream = StringIO(s)

tests/test_config_instance.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,3 +685,34 @@ def test_if_else_complex():
685685
"""
686686
).resolve(registry=registry)
687687
assert config["params"]["c"] == 12
688+
689+
690+
def test_very_long_yaml_config():
691+
config = Config.from_yaml_str(
692+
"""\
693+
a: {}
694+
""".format(
695+
"x" * 4200
696+
)
697+
).resolve(registry=registry)
698+
assert config == {"a": "x" * 4200}
699+
700+
701+
def test_escaped_string():
702+
config = Config.from_yaml_str(
703+
"""
704+
test:
705+
a: "1"
706+
section:
707+
num: 1
708+
escaped_num: "1"
709+
real_ref: ${test.a}
710+
escaped_broken_ref: "${test.a"
711+
escaped_ref: "${test.a}"
712+
"""
713+
).resolve(registry=registry)
714+
assert config["section"]["num"] == 1
715+
assert config["section"]["escaped_num"] == "1"
716+
assert config["section"]["real_ref"] == "1"
717+
assert config["section"]["escaped_broken_ref"] == "${test.a"
718+
assert config["section"]["escaped_ref"] == "${test.a}"

0 commit comments

Comments
 (0)