Skip to content

Commit b1b38d8

Browse files
committed
gh-59598: Strip leading whitespace in JSONDecoder.raw_decode
raw_decode currently ignores leading whitespace before JSON values, raising JSONDecodeError on strings like ' {"key": "value"}'. This is inconsistent with JSONDecoder.decode() which handles leading whitespace. Add s = s.lstrip() at the start of raw_decode to strip leading whitespace before decoding, matching the behavior of decode().
1 parent cfe3e07 commit b1b38d8

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

Lib/json/decoder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ def raw_decode(self, s, idx=0):
370370
have extraneous data at the end.
371371
372372
"""
373+
s = s.lstrip()
374+
373375
try:
374376
obj, end = self.scan_once(s, idx)
375377
except StopIteration as err:

0 commit comments

Comments
 (0)