One function
scanKeyName in hjson/hjson-py
The author described this change as “fix trailing whitespace in keyname”. It counts as a record because the check below fails on the code as it stood at f1e3ed863 and passes on 06b136fc6, with nothing else changed between the two runs.
Projecthjson/hjson-py
Fix saved2016-02-04
Sharing licenceMIT · LICENSE.txt
Change size+13 −5
What the code was meant to do, written into the code itself as a docstring
Scan the string s for a JSON/Hjson key. see scanstring
The change
| 7 | 7 | return scanstring(s, end + 1, encoding, strict) | |
| 8 | 8 | ||
| 9 | 9 | begin = end | |
| 10 | + | space = -1 | |
| 10 | 11 | while 1: | |
| 11 | 12 | ch = s[end:end + 1] | |
| 12 | 13 | ||
| 13 | - | if ch == ':': | |
| 14 | + | if ch == '': | |
| 15 | + | raise HjsonDecodeError("Bad key name (eof)", s, end); | |
| 16 | + | elif ch == ':': | |
| 14 | 17 | if begin == end: | |
| 15 | 18 | raise HjsonDecodeError("Found ':' but no key name (for an empty key name use quotes)", s, begin) | |
| 16 | - | return s[begin:end], end | |
| 17 | - | elif ch in WHITESPACE or ch == '{' or ch == '}' or ch == '[' or ch == ']' or ch == ',': | |
| 19 | + | elif space >= 0: | |
| 20 | + | if space != end - 1: raise HjsonDecodeError("Found whitespace in your key name (use quotes to include)", s, space) | |
| 21 | + | return s[begin:end].rstrip(), end | |
| 22 | + | else: | |
| 23 | + | return s[begin:end], end | |
| 24 | + | elif ch in WHITESPACE: | |
| 25 | + | if space < 0 or space == end - 1: space = end | |
| 26 | + | elif ch == '{' or ch == '}' or ch == '[' or ch == ']' or ch == ',': | |
| 18 | 27 | raise HjsonDecodeError("Found '" + ch + "' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace)", s, begin) | |
| 19 | - | else: | |
| 20 | - | end += 1 | |
| 28 | + | end += 1 |
The check that tells the two apart
fail→pass·hjson/tests/test_fail.py::TestFail::test_truncated_input
Check file hjson/tests/test_fail.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before itf1e3ed86393eff4bdb1c55521add84e468ae0488
Broken version dated2015-08-21
Modulehjson.decoder
Units changedscanKeyName
Fingerprint269eff559171c24f
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in hjson/hjson-py
- 2015-01-10scankey