Skip to content

Commit d58df5c

Browse files
author
Overhang.IO
committed
Merge remote-tracking branch 'origin/master' into nightly
2 parents 6941021 + 51928b0 commit d58df5c

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [Bugfix] Correctly parse strings prefixed with pound "#" key in `tutor config save --set KEY=#value` commands. (by @regisb)

tests/test_serialize.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def test_parse_key_value(self) -> None:
4141
"x=key1:\n subkey: value\nkey2:\n subkey: value"
4242
),
4343
)
44+
self.assertEqual(
45+
("INDIGO_PRIMARY_COLOR", "#225522"),
46+
serialize.parse_key_value("INDIGO_PRIMARY_COLOR=#225522"),
47+
)
4448

4549
def test_str_format(self) -> None:
4650
self.assertEqual("true", serialize.str_format(True))

tutor/serialize.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,8 @@ def parse_key_value(text: str) -> t.Optional[tuple[str, t.Any]]:
7373
if not value:
7474
# Empty strings are interpreted as null values, which is incorrect.
7575
value = "''"
76+
elif "\n" not in value and value.startswith("#"):
77+
# Single-line string that starts with a pound # key
78+
# We need to escape the string, otherwise pound will be interpreted as a comment.
79+
value = f'"{value}"'
7680
return key, parse(value)

0 commit comments

Comments
 (0)