Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-04-18 08:42:58 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2024-04-18 08:42:58 +1000
commit1587bb240925dc7e3d549fd6d0fed101d6036ce7 (patch)
tree8eb9ddf2674c80a3fccc6e37943e630e3652ea2c
parent83ca73b299d6d6df810eeb0ebff803f67d7be3ac (diff)
Empty JSON objects should be printed as {}, not { \n} + fix the new Json hasher not sorting keys
[skip ci]
-rw-r--r--source/core/StarJson.cpp14
-rw-r--r--source/core/StarJsonParser.hpp9
2 files changed, 16 insertions, 7 deletions
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<JsonObjectConstPtr>()) {
- hasher.push(pair.first.utf8Ptr(), pair.first.utf8Size());
- pair.second.getHash(hasher);
+ auto& object = *m_data.get<JsonObjectConstPtr>();
+ List<JsonObject::const_iterator> 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);
}
}
}
diff --git a/source/core/StarJsonParser.hpp b/source/core/StarJsonParser.hpp
index 91d93bb..c7a9cc6 100644
--- a/source/core/StarJsonParser.hpp
+++ b/source/core/StarJsonParser.hpp
@@ -521,11 +521,12 @@ public:
}
void endObject() {
+ if (currentState() == ObjectElement) {
+ if (m_pretty)
+ write('\n');
+ indent();
+ }
popState(Object);
-
- if (m_pretty)
- write('\n');
- indent();
write('}');
}