Skip to content

Commit

Permalink
Fix Json array clone
Browse files Browse the repository at this point in the history
  • Loading branch information
gedaiu committed Jan 10, 2019
1 parent 01cdf30 commit 01cc20c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions data/vibe/data/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,10 @@ struct Json {
case Type.float_: return Json(m_float);
case Type.string: return Json(m_string);
case Type.array:
auto ret = Json.emptyArray;
Json[] ret;
foreach (v; this.byValue) ret ~= v.clone();
return ret;

return Json(ret);
case Type.object:
auto ret = Json.emptyObject;
foreach (name, v; this.byKeyValue) ret[name] = v.clone();
Expand Down Expand Up @@ -2111,6 +2112,16 @@ struct JsonStringSerializer(R, bool pretty = false)
}
}

/// Cloning JSON arrays
unittest
{
Json value = Json([ Json([ Json.emptyArray ]), Json.emptyArray ]).clone;

assert(value.length == 2);
assert(value[0].length == 1);
assert(value[0][0].length == 0);
}

unittest
{
assert(serializeToJsonString(double.nan) == "null");
Expand Down

0 comments on commit 01cc20c

Please sign in to comment.