From 01cc20c17973fd4348ce866ab46038a6567356c3 Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Thu, 10 Jan 2019 10:33:33 +0100 Subject: [PATCH] Fix Json array clone --- data/vibe/data/json.d | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/data/vibe/data/json.d b/data/vibe/data/json.d index d20c4a36eb..bba60afa79 100644 --- a/data/vibe/data/json.d +++ b/data/vibe/data/json.d @@ -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(); @@ -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");