Skip to content

Commit 7d63a2e

Browse files
committed
Fix issue with static arrays, and with skipping items.
1 parent 6882428 commit 7d63a2e

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

source/iopipe/json/parser.d

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,14 +1592,18 @@ struct JSONTokenizer(Chain, ParseConfig cfg)
15921592
case ObjectEnd:
15931593
case ArrayEnd:
15941594
if(!depth)
1595+
{
1596+
// this is the end of the *parent* object or array. Don't skip it.
1597+
return item;
1598+
}
1599+
else if(--depth == 0)
15951600
{
15961601
// at the end of the current object. Skip the end piece, and move on.
1597-
auto n = next;
1602+
auto n = nextSignificant;
15981603
if(n.token == Error)
15991604
return n.token;
1600-
return peek;
1605+
return peekSignificant;
16011606
}
1602-
--depth;
16031607
break;
16041608
case Comma:
16051609
if(depth == 0)
@@ -1610,10 +1614,7 @@ struct JSONTokenizer(Chain, ParseConfig cfg)
16101614
return item;
16111615
default:
16121616
// everything else we ignore
1613-
auto n = next;
1614-
if(n.token == Error)
1615-
return n.token;
1616-
continue;
1617+
break;
16171618
}
16181619
cast(void)next; // skip this item
16191620
}

source/iopipe/json/serialize.d

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ OBJ_MEMBER_SWITCH:
443443
JSONValue!SType newItem;
444444
tokenizer.deserializeImpl(newItem, relPol);
445445
__traits(getMember, item, extrasMember).object[name.to!(immutable(SType))] = newItem;
446-
break;
446+
break OBJ_MEMBER_SWITCH;
447447
}}
448448
else
449449
{
@@ -851,6 +851,13 @@ void serializeImpl(T, Char)(scope void delegate(const(Char)[]) w, ref T val) if
851851
serializeImpl(w, val[]);
852852
}
853853

854+
unittest
855+
{
856+
// ensure static array serialization works
857+
int[5] arr = [1,2,3,4,5];
858+
assert(serialize(arr) == "[1, 2, 3, 4, 5]");
859+
}
860+
854861
void serializeImpl(T, Char)(scope void delegate(const(Char)[]) w, ref T val) if (is(T == enum))
855862
{
856863
// enums are special, serialize based on the name. Unless there's a UDA
@@ -867,7 +874,7 @@ void serializeImpl(T, Char)(scope void delegate(const(Char)[]) w, ref T val) if
867874
}
868875
}
869876

870-
void serializeImpl(T, Char)(scope void delegate(const(Char)[]) w, ref T val) if (isDynamicArray!T && !isSomeString!T && !is(T == enum))
877+
void serializeImpl(T, Char)(scope void delegate(const(Char)[]) w, T val) if (isDynamicArray!T && !isSomeString!T && !is(T == enum))
871878
{
872879
// open brace
873880
w("[");
@@ -883,7 +890,7 @@ void serializeImpl(T, Char)(scope void delegate(const(Char)[]) w, ref T val) if
883890
w("]");
884891
}
885892

886-
void serializeImpl(T, Char)(scope void delegate(const(Char)[]) w, ref T val) if (is(T == V[K], V, K) /* && isSomeString!K */)
893+
void serializeImpl(T, Char)(scope void delegate(const(Char)[]) w, T val) if (is(T == V[K], V, K) /* && isSomeString!K */)
887894
{
888895
assert(is(T == V[K], V, K));
889896
enum useKW = !isSomeString!K;
@@ -949,7 +956,7 @@ unittest
949956
assert(serialized == `{"a" : 1, "b" : 2}` || serialized == `{"b" : 2, "a" : 1}`);
950957
}
951958

952-
void serializeImpl(T, Char)(scope void delegate(const(Char)[]) w, ref T val) if (isSomeString!T)
959+
void serializeImpl(T, Char)(scope void delegate(const(Char)[]) w, T val) if (isSomeString!T)
953960
{
954961
w(`"`);
955962
put(w, val);

0 commit comments

Comments
 (0)