diff --git a/Fleece/Core/JSONConverter.cc b/Fleece/Core/JSONConverter.cc index e8edd624..c358cf80 100644 --- a/Fleece/Core/JSONConverter.cc +++ b/Fleece/Core/JSONConverter.cc @@ -32,7 +32,7 @@ namespace fleece { namespace impl { JSONConverter::JSONConverter(Encoder &e) noexcept :_encoder(e), - _jsn(jsonsl_new(50)), // never returns nullptr, according to source code + _jsn(jsonsl_new(102)), // never returns nullptr, according to source code. 102 allows 100 logical levels. _jsonError(JSONSL_ERROR_SUCCESS), _errorPos(0) { diff --git a/Tests/ValueTests.cc b/Tests/ValueTests.cc index 0cba28c7..f7ec136a 100644 --- a/Tests/ValueTests.cc +++ b/Tests/ValueTests.cc @@ -259,4 +259,41 @@ namespace fleece { // (calling FLDictIterator_Next would be illegal) FLDoc_Release(doc); } + + TEST_CASE("Many Levels in a Doc", "[Doc]") { + auto genDoc = [](unsigned nlevels) -> string { + // pre-condition: nlevels >= 1 + string ret = ""; + for (unsigned i = 1; i <= nlevels; ++i) { + ret += R"({"a":)"; + } + ret += "1}"; + for (unsigned i = 2; i <= nlevels; ++i) { + ret += "}"; + } + return ret; + }; + + SECTION("100 Levels of JSON Dictionary") { + alloc_slice origJSON{genDoc(100)}; + Retained doc = Doc::fromJSON(origJSON); + auto root = doc->root(); + alloc_slice json = root->toJSON(); + CHECK(origJSON == json); + retain(root); + release(root); + } + + SECTION("100 Is the Limit of JSON Dictionary") { + alloc_slice origJSON{genDoc(101)}; + Retained doc; + fleece::ErrorCode errCode = fleece::NoError; + try { + doc = Doc::fromJSON(origJSON); + } catch (FleeceException& exc) { + errCode = fleece::JSONError; + } + CHECK(errCode == fleece::JSONError); + } + } }