mirror of
https://github.com/ChristianLight/tutor.git
synced 2025-01-11 09:35:06 +00:00
Fix incorrectly parsed empty strings in config save --set ...=...
When running `config save --set KEY=""`, KEY was incorrectly interpreted as null.
This commit is contained in:
parent
eeb5f43239
commit
731de6a747
@ -2,6 +2,10 @@
|
||||
|
||||
Note: Breaking changes between versions are indicated by "💥".
|
||||
|
||||
## Unreleased
|
||||
|
||||
- [Bugfix] Fix incorrectly parsed empty strings for `config save --set ...=...` commands
|
||||
|
||||
## 3.11.2 (2020-01-17)
|
||||
|
||||
- [Bugfix] Make sure `docker-compose.override.yml` are loaded in dev and local contexts
|
||||
|
@ -25,3 +25,11 @@ class SerializeTests(unittest.TestCase):
|
||||
|
||||
def test_parse_weird_chars(self):
|
||||
self.assertEqual("*@google.com", serialize.parse("*@google.com"))
|
||||
|
||||
def test_parse_empty_string(self):
|
||||
self.assertEqual("", serialize.parse("''"))
|
||||
|
||||
# def test_dump_null(self):# # Unfortunately, this fails as the output is "null\n...\n"
|
||||
|
||||
|
||||
# self.assertEqual("null", serialize.dumps(None))
|
||||
|
@ -25,6 +25,10 @@ class YamlParamType(click.ParamType):
|
||||
k, v = value.split("=")
|
||||
except ValueError:
|
||||
self.fail("'{}' is not of the form 'key=value'.".format(value), param, ctx)
|
||||
if not v:
|
||||
# Empty strings are incorrectly interpreted as null values, which is
|
||||
# incorrect.
|
||||
v = "''"
|
||||
return k, serialize.parse(v)
|
||||
|
||||
|
||||
@ -93,6 +97,7 @@ def printroot(context):
|
||||
def printvalue(context, key):
|
||||
config = tutor_config.load(context.root)
|
||||
try:
|
||||
# Note that this will incorrectly print None values
|
||||
fmt.echo(config[key])
|
||||
except KeyError:
|
||||
raise exceptions.TutorError("Missing configuration value: {}".format(key))
|
||||
|
@ -8,7 +8,11 @@ def load(stream):
|
||||
|
||||
|
||||
def dump(content, fileobj):
|
||||
yaml.dump(content, fileobj, default_flow_style=False)
|
||||
yaml.dump(content, stream=fileobj, default_flow_style=False)
|
||||
|
||||
|
||||
def dumps(content):
|
||||
return yaml.dump(content, stream=None, default_flow_style=False)
|
||||
|
||||
|
||||
def parse(v):
|
||||
|
Loading…
Reference in New Issue
Block a user