Skip to content

Commit

Permalink
fix quoteless string starting with punctuator
Browse files Browse the repository at this point in the history
  • Loading branch information
laktak committed Aug 2, 2016
1 parent 4cb5364 commit f63efcd
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 6 deletions.
2 changes: 2 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,5 1,7 @@
# History

- v2.0.0
- fix quoteless string starting with punctuator
- v1.5.8
- add CLI scripts for pip
- v1.5.6
Expand Down
2 changes: 1 addition & 1 deletion hjson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 36,7 @@
"""
from __future__ import absolute_import
__version__ = '1.5.8'
__version__ = '2.0.0'
__all__ = [
'dump', 'dumps', 'load', 'loads',
'dumpJSON', 'dumpsJSON',
Expand Down
4 changes: 4 additions & 0 deletions hjson/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 25,7 @@ def _floatconstants():
NaN, PosInf, NegInf = _floatconstants()

WHITESPACE = ' \t\n\r'
PUNCTUATOR = '{}[],:'

NUMBER_RE = re.compile(r'[\t ]*(-?(?:0|[1-9]\d*))(\.\d )?([eE][- ]?\d )?[\t ]*')
STRINGCHUNK = re.compile(r'(.*?)(["\\\x00-\x1f])', FLAGS)
Expand Down Expand Up @@ -218,6 219,9 @@ def scantfnns(context, s, end):
chf, begin = getNext(s, end)
end = begin

if chf in PUNCTUATOR:
raise HjsonDecodeError("Found a punctuator character when excpecting a quoteless string (check your syntax)", s, end);

while 1:
ch = s[end:end 1]

Expand Down
2 changes: 2 additions & 0 deletions hjson/tests/assets/fail34_test.json
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
A quoteless string is OK,
but two must be contained in an array.
4 changes: 4 additions & 0 deletions hjson/tests/assets/failStr1_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 1,4 @@
{
# invalid quoteless string
ql: ]
}
4 changes: 4 additions & 0 deletions hjson/tests/assets/failStr2_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 1,4 @@
{
# invalid quoteless string
ql: }
}
4 changes: 4 additions & 0 deletions hjson/tests/assets/failStr3_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 1,4 @@
{
# invalid quoteless string
ql: {
}
4 changes: 4 additions & 0 deletions hjson/tests/assets/failStr4_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 1,4 @@
{
# invalid quoteless string
ql: [
}
4 changes: 4 additions & 0 deletions hjson/tests/assets/failStr5_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 1,4 @@
{
# invalid quoteless string
ql: :
}
4 changes: 4 additions & 0 deletions hjson/tests/assets/failStr6_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 1,4 @@
{
# invalid quoteless string
ql: ,
}
2 changes: 1 addition & 1 deletion hjson/tests/assets/passSingle_result.hjson
Original file line number Diff line number Diff line change
@@ -1 1 @@
foo=bar
allow quoteless strings
2 changes: 1 addition & 1 deletion hjson/tests/assets/passSingle_result.json
Original file line number Diff line number Diff line change
@@ -1 1 @@
"foo=bar"
"allow quoteless strings"
2 changes: 1 addition & 1 deletion hjson/tests/assets/passSingle_test.hjson
Original file line number Diff line number Diff line change
@@ -1 1 @@
foo=bar
allow quoteless strings
54 changes: 54 additions & 0 deletions hjson/tests/assets/testlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 1,54 @@
charset_test.hjson
comments_test.hjson
empty_test.hjson
fail10_test.json
fail11_test.json
fail12_test.json
fail13_test.json
fail14_test.json
fail15_test.json
fail16_test.json
fail17_test.json
fail19_test.json
fail20_test.json
fail21_test.json
fail22_test.json
fail23_test.json
fail24_test.json
fail26_test.json
fail28_test.json
fail29_test.json
fail2_test.json
fail30_test.json
fail31_test.json
fail32_test.json
fail33_test.json
fail34_test.json
fail5_test.json
fail6_test.json
fail7_test.json
fail8_test.json
failKey1_test.hjson
failKey2_test.hjson
failKey3_test.hjson
failObj1_test.hjson
failObj2_test.hjson
failObj3_test.hjson
failStr1_test.hjson
failStr2_test.hjson
failStr3_test.hjson
failStr4_test.hjson
failStr5_test.hjson
failStr6_test.hjson
kan_test.hjson
keys_test.hjson
oa_test.hjson
pass1_test.json
pass2_test.json
pass3_test.json
pass4_test.json
passSingle_test.hjson
root_test.hjson
stringify1_test.hjson
strings_test.hjson
trail_test.hjson
2 changes: 1 addition & 1 deletion hjson/tests/test_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 123,7 @@ def test_truncated_input(self):
('{"spam":42,', 'Bad key name (eof)', 11),
('"', 'Unterminated string starting at', 0),
('"spam', 'Unterminated string starting at', 0),
('[,', "Expecting value", 2),
('[,', "Found a punctuator character", 1),
]
for data, msg, idx in test_cases:
try:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 10,7 @@
DistutilsPlatformError

IS_PYPY = hasattr(sys, 'pypy_translation_info')
VERSION = '1.5.8'
VERSION = '2.0.0'
DESCRIPTION = "JSON for Humans. A configuration file format with relaxed syntax, fewer mistakes and more comments."

with open('README.rst', 'r') as f:
Expand Down

0 comments on commit f63efcd

Please sign in to comment.