Fixed static JsonString not being saved by reference

This commit is contained in:
Benoit Blanchon
2020-02-16 16:20:24 +01:00
parent 58298ec5ba
commit e6ddfc7afb
2 changed files with 6 additions and 5 deletions

View File

@ -79,7 +79,7 @@ TEST_CASE("JsonVariant and strings") {
variant.set(JsonString(str, true));
strcpy(str, "world");
REQUIRE(variant == "hello");
REQUIRE(variant == "world");
}
SECTION("stores non-static JsonString by copy") {

View File

@ -53,10 +53,11 @@ class StringAdapter : public RamStringAdapter {
return _isStatic;
}
/* const char* save(MemoryPool* pool) const {
if (_isStatic) return c_str();
return RamStringAdapter::save(pool);
}*/
const char* save(MemoryPool* pool) const {
if (_isStatic)
return data();
return RamStringAdapter::save(pool);
}
private:
bool _isStatic;