diff options
| author | Bob Ippolito <bob@redivi.com> | 2015-05-18 11:46:23 -0700 |
|---|---|---|
| committer | Bob Ippolito <bob@redivi.com> | 2015-05-18 11:50:48 -0700 |
| commit | e18cc09b688ea1f3305c27616fd3cadd2adc6d31 (patch) | |
| tree | 6267f941930ec8772290abed7b8e9a6309c80aab /simplejson/encoder.py | |
| parent | f9e8ca4be17a32067e02805e7771635ee2af4aa3 (diff) | |
| download | simplejson-e18cc09b688ea1f3305c27616fd3cadd2adc6d31.tar.gz | |
no longer trust custom repr for int/long/float subclasses #118v3.7.0
Diffstat (limited to 'simplejson/encoder.py')
| -rw-r--r-- | simplejson/encoder.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/simplejson/encoder.py b/simplejson/encoder.py index db18244..7f0b037 100644 --- a/simplejson/encoder.py +++ b/simplejson/encoder.py @@ -311,6 +311,9 @@ class JSONEncoder(object): elif o == _neginf: text = '-Infinity' else: + if type(o) != float: + # See #118, do not trust custom str/repr + o = float(o) return _repr(o) if ignore_nan: @@ -412,6 +415,9 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, or _int_as_string_bitcount < 1 ) + if type(value) not in integer_types: + # See #118, do not trust custom str/repr + value = int(value) if ( skip_quoting or (-1 << _int_as_string_bitcount) @@ -501,6 +507,9 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, elif key is None: key = 'null' elif isinstance(key, integer_types): + if key not in integer_types: + # See #118, do not trust custom str/repr + key = int(key) key = str(key) elif _use_decimal and isinstance(key, Decimal): key = str(key) |
