Skip to content
Open
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: 1 addition & 1 deletion bin/jsonpointer
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def resolve_files():

try:
doc = json.load(f)
except (json.JSONDecodeError, UnicodeDecodeError) as e:
except ValueError as e:
if not args.continue_on_error:
raise
print('Could not parse JSON in %r: %s' % (name, e),
Expand Down
33 changes: 33 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,39 @@ def test_invalid_json_in_one_file(self):
proc.stderr)
self.assertNotIn('Traceback', proc.stderr)

@unittest.skipUnless(hasattr(sys, 'get_int_max_str_digits'),
'Integer string conversion limits are not available')
def test_large_json_integer_in_one_file(self):
self._write('large-integer.json', '{"a": ' + '1' * 641 + '}')
with mock.patch.dict(os.environ, {'PYTHONINTMAXSTRDIGITS': '640'}):
for index in range(3):
with self.subTest(index=index):
files = ['a.json', 'b.json']
files.insert(index, 'large-integer.json')
proc = self._run('--continue-on-error', '/a', *files)
self.assertEqual(proc.returncode, 1)
self.assertEqual(proc.stdout, self.A_OUT + self.B_OUT)
self.assertIn(
"Could not parse JSON in 'large-integer.json':",
proc.stderr)
self.assertIn('digits', proc.stderr)
self.assertNotIn('Traceback', proc.stderr)

@unittest.skipUnless(hasattr(sys, 'get_int_max_str_digits'),
'Integer string conversion limits are not available')
def test_large_json_integer_stops_without_continue_on_error(self):
self._write('large-integer.json', '{"a": ' + '1' * 641 + '}')
with mock.patch.dict(os.environ, {'PYTHONINTMAXSTRDIGITS': '640'}):
for index in range(3):
with self.subTest(index=index):
files = ['a.json', 'b.json']
files.insert(index, 'large-integer.json')
proc = self._run('/a', *files)
self.assertEqual(proc.returncode, 1)
self.assertEqual(
proc.stdout, ''.join([self.A_OUT, self.B_OUT][:index]))
self.assertIn('ValueError', proc.stderr)

def test_invalid_json_and_unresolvable_pointer(self):
self._write('invalid.json', '{"a": }')
proc = self._run('--continue-on-error', '/b',
Expand Down
Loading