Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.14] gh-143196: Fix crash in non-standard use of internal JSON encoder object (GH-143618)#143748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall 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
31 changes: 31 additions & 0 deletionsLib/test/test_json/test_speedups.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,3 +80,34 @@ def test(name):
def test_unsortable_keys(self):
with self.assertRaises(TypeError):
self.json.encoder.JSONEncoder(sort_keys=True).encode({'a': 1, 1: 'a'})

def test_current_indent_level(self):
enc = self.json.encoder.c_make_encoder(
markers=None,
default=str,
encoder=self.json.encoder.c_encode_basestring,
indent='\t',
key_separator=': ',
item_separator=', ',
sort_keys=False,
skipkeys=False,
allow_nan=False)
expected = (
'[\n'
'\t"spam", \n'
'\t{\n'
'\t\t"ham": "eggs"\n'
'\t}\n'
']')
self.assertEqual(enc(['spam', {'ham': 'eggs'}], 0)[0], expected)
self.assertEqual(enc(['spam', {'ham': 'eggs'}], -3)[0], expected)
expected2 = (
'[\n'
'\t\t\t\t"spam", \n'
'\t\t\t\t{\n'
'\t\t\t\t\t"ham": "eggs"\n'
'\t\t\t\t}\n'
'\t\t\t]')
self.assertEqual(enc(['spam', {'ham': 'eggs'}], 3)[0], expected2)
self.assertRaises(TypeError, enc, ['spam', {'ham': 'eggs'}], 3.0)
self.assertRaises(TypeError, enc, ['spam', {'ham': 'eggs'}])
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Fix crash when the internal encoder object returned by undocumented function
:func:`!json.encoder.c_make_encoder` was called with non-zero second
(*_current_indent_level*) argument.
1 change: 1 addition & 0 deletionsModules/_json.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1383,6 +1383,7 @@ encoder_call(PyObject *op, PyObject *args, PyObject *kwds)
return NULL;
}
}
indent_level = 0;
if (encoder_listencode_obj(self, writer, obj, indent_level, indent_cache)) {
PyUnicodeWriter_Discard(writer);
Py_XDECREF(indent_cache);
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp