mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-12-12 14:17:46 +00:00
fix: parse strings prefixed with "#" in config save --set ...
Pound keys were interpreted as comments. This is annoying when we want to parse html color codes, such as in: $ tutor config save --set "INDIGO_PRIMARY_COLOR=#225522" $ tutor config printvalue INDIGO_PRIMARY_COLOR null Close #866.
This commit is contained in:
parent
8eccaa61e9
commit
51928b0075
@ -0,0 +1 @@
|
|||||||
|
- [Bugfix] Correctly parse strings prefixed with pound "#" key in `tutor config save --set KEY=#value` commands. (by @regisb)
|
@ -41,6 +41,10 @@ class SerializeTests(unittest.TestCase):
|
|||||||
"x=key1:\n subkey: value\nkey2:\n subkey: value"
|
"x=key1:\n subkey: value\nkey2:\n subkey: value"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
("INDIGO_PRIMARY_COLOR", "#225522"),
|
||||||
|
serialize.parse_key_value("INDIGO_PRIMARY_COLOR=#225522"),
|
||||||
|
)
|
||||||
|
|
||||||
def test_str_format(self) -> None:
|
def test_str_format(self) -> None:
|
||||||
self.assertEqual("true", serialize.str_format(True))
|
self.assertEqual("true", serialize.str_format(True))
|
||||||
|
@ -73,4 +73,8 @@ def parse_key_value(text: str) -> t.Optional[tuple[str, t.Any]]:
|
|||||||
if not value:
|
if not value:
|
||||||
# Empty strings are interpreted as null values, which is incorrect.
|
# Empty strings are interpreted as null values, which is incorrect.
|
||||||
value = "''"
|
value = "''"
|
||||||
|
elif "\n" not in value and value.startswith("#"):
|
||||||
|
# Single-line string that starts with a pound # key
|
||||||
|
# We need to escape the string, otherwise pound will be interpreted as a comment.
|
||||||
|
value = f'"{value}"'
|
||||||
return key, parse(value)
|
return key, parse(value)
|
||||||
|
Loading…
Reference in New Issue
Block a user