From 1587bb240925dc7e3d549fd6d0fed101d6036ce7 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Thu, 18 Apr 2024 08:42:58 +1000 Subject: Empty JSON objects should be printed as {}, not { \n} + fix the new Json hasher not sorting keys [skip ci] --- source/core/StarJson.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'source/core/StarJson.cpp') diff --git a/source/core/StarJson.cpp b/source/core/StarJson.cpp index 83b4e67..04ac544 100644 --- a/source/core/StarJson.cpp +++ b/source/core/StarJson.cpp @@ -981,9 +981,17 @@ void Json::getHash(XXHash3& hasher) const { json.getHash(hasher); } else if (type == Json::Type::Object) { - for (auto const& pair : *m_data.get()) { - hasher.push(pair.first.utf8Ptr(), pair.first.utf8Size()); - pair.second.getHash(hasher); + auto& object = *m_data.get(); + List iterators; + iterators.reserve(object.size()); + for (auto i = object.begin(); i != object.end(); ++i) + iterators.append(i); + iterators.sort([](JsonObject::const_iterator a, JsonObject::const_iterator b) { + return a->first < b->first; + }); + for (auto& iter : iterators) { + hasher.push(iter->first.utf8Ptr(), iter->first.utf8Size()); + iter->second.getHash(hasher); } } } -- cgit v1.2.3