diff --git a/json5/tool.py b/json5/tool.py index 05b27b2..f4b6bdb 100644 --- a/json5/tool.py +++ b/json5/tool.py @@ -45,7 +45,7 @@ def main(argv=None, host=None): host.print(__version__) return 0 - if args.cmd: + if args.cmd is not None: inp = args.cmd elif args.file == '-': inp = host.stdin.read() diff --git a/tests/tool_test.py b/tests/tool_test.py index 81934f6..647b368 100644 --- a/tests/tool_test.py +++ b/tests/tool_test.py @@ -200,6 +200,18 @@ def test_keys_are_quoted_by_default(self): def test_read_command(self): self.check(['-c', '"foo"'], out='"foo"\n') + def test_read_empty_command(self): + # An empty -c string is still the input; stdin and FILE are not read. + err = 'Empty strings are not legal JSON5\n' + self.check(['-c', ''], stdin='"foo"', returncode=1, out='', err=err) + self.check( + ['-c', '', 'foo.json5'], + files={'foo.json5': '"foo"\n'}, + returncode=1, + out='', + err=err, + ) + def test_read_from_stdin(self): self.check([], stdin='"foo"\n', out='"foo"\n')