Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jsonpatch_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def patch_files():
# The inputs are closed before anything is written, as Windows cannot
# replace ORIGINAL while it is open.
with _input_files(args.ORIGINAL, args.PATCH):
if args.in_place and args.ORIGINAL is sys.stdin:
raise ValueError('--in-place requires ORIGINAL to be a file')
doc = _load(args.ORIGINAL)
patch = _load(args.PATCH, jsonpatch.JsonPatch.from_string)
result = patch.apply(doc)
Expand Down
10 changes: 10 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3740,6 +3740,16 @@ def test_jsonpatch_in_place(self):
# the temporary file has been moved over the original
self.assertEqual(sorted(os.listdir(self.dir)), ['doc.json', 'patch.json'])

def test_jsonpatch_in_place_rejects_standard_input_as_original(self):
patch = self.write('patch.json', [])
for stdin in ('{}', 'invalid JSON'):
with self.subTest(stdin=stdin):
res = self.run_script('jsonpatch', '--in-place', '-', patch,
stdin=stdin, cwd=self.dir)
self.assertEqual((res.returncode, res.stdout), (2, ''), res.stderr)
self.assertEqual(res.stderr, 'jsonpatch: error: --in-place requires ORIGINAL to be a file\n')
self.assertEqual(os.listdir(self.dir), ['patch.json'])

def test_jsonpatch_in_place_utf8_without_utf8_mode(self):
for atomic in (True, False):
with self.subTest(atomic=atomic):
Expand Down
Loading