Skip to content

Commit 59cf273

Browse files
committed
add test for key:[array] and fix regular expression to handle it
1 parent 3b3388c commit 59cf273

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

jsol.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@
7979
// Logic borrowed from http://json.org/json2.js
8080
if ( /^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
8181
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
82-
.replace(/(?:^|:|,)(?:\s*\[)+/g, "")
82+
.replace(/(?:^|:|,)(?:\s*\[)+/g, ":")
8383
/** everything up to this point is json2.js **/
8484
/** this is the 5th stage where it accepts unquoted keys **/
85-
.replace(/[A-Za-z_]\w*\s*\:/g, ":")) ) {
85+
.replace(/\w*\s*\:/g, ":")) ) {
8686
return (new Function("return " + text))();
8787
}
8888
else {

test/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ test("valid mixed", 1, function() {
1313
deepEqual(JSOL.parse(jsol), {hello:"world", foo:2, bar:false});
1414
});
1515

16+
test("valid key value array", 1, function() {
17+
var jsol = '{hello:[{world:"hello"}]}';
18+
deepEqual(JSOL.parse(jsol), {hello:[{world:"hello"}]});
19+
});
20+
1621
test("invalid function call", 1, function() {
1722
try {
1823
function callme() {alert("hello?");};

0 commit comments

Comments
 (0)