fix: allow colon in options interpolation

This commit is contained in:
Evgenii Alekseev 2024-09-23 13:52:49 +03:00
parent b319e89e41
commit cd61ab3e5b
2 changed files with 8 additions and 1 deletions

View File

@ -52,7 +52,7 @@ class ShellInterpolator(configparser.Interpolation):
def identifiers() -> Generator[tuple[str | None, str], None, None]:
# extract all found identifiers and parse them
for identifier in ShellTemplate(value).get_identifiers():
match identifier.split(":"):
match identifier.rsplit(":", maxsplit=1):
case [lookup_option]: # single option from the same section
yield None, lookup_option
case [lookup_section, lookup_option]: # reference to another section

View File

@ -24,6 +24,9 @@ def _parser() -> dict[str, dict[str, str]]:
"key3": "${section1:home}",
"key5": "${section1:key4}",
},
"section4:suffix": {
"key6": "value6"
},
}
@ -45,6 +48,10 @@ def test_extract_variables() -> None:
assert not dict(ShellInterpolator._extract_variables(parser, "${section4:key1}", parser["section1"]))
assert dict(ShellInterpolator._extract_variables(parser, "${section4:suffix:key6}", parser["section1"])) == {
"section4:suffix:key6": "value6",
}
def test_environment() -> None:
"""