fix(DynamicStruct): toString not wrapping empty strings #3835

This commit is contained in:
Alex Fabijanic 2022-10-13 15:25:35 +02:00
parent a2c09c29d8
commit 9c8a92da3d
3 changed files with 15 additions and 0 deletions

View File

@ -72,6 +72,10 @@ void appendJSONValue(std::string& val, const Var& any, bool wrap)
{
val.append("null");
}
else if (any.isString() && any.extract<std::string>().empty())
{
val.append("\"\"");
}
else
{
bool isStr = wrap && isJSONString(any);

View File

@ -2286,6 +2286,15 @@ void VarTest::testOrderedDynamicStructBasics()
}
void VarTest::testDynamicStructEmptyString()
{
DynamicStruct aStruct;
aStruct["Empty"] = "";
aStruct["Space"] = " ";
assertEqual(aStruct.toString(false), "{ \"Empty\": \"\", \"Space\": \" \" }");
}
void VarTest::testDynamicStructNoEscapeString()
{
DynamicStruct aStruct;
@ -3139,6 +3148,7 @@ CppUnit::Test* VarTest::suite()
CppUnit_addTest(pSuite, VarTest, testDynamicPair);
CppUnit_addTest(pSuite, VarTest, testDynamicStructBasics);
CppUnit_addTest(pSuite, VarTest, testOrderedDynamicStructBasics);
CppUnit_addTest(pSuite, VarTest, testDynamicStructEmptyString);
CppUnit_addTest(pSuite, VarTest, testDynamicStructNoEscapeString);
CppUnit_addTest(pSuite, VarTest, testDynamicStructString);
CppUnit_addTest(pSuite, VarTest, testOrderedDynamicStructString);

View File

@ -57,6 +57,7 @@ public:
void testDynamicStructBasics();
void testOrderedDynamicStructBasics();
void testDynamicStructString();
void testDynamicStructEmptyString();
void testDynamicStructNoEscapeString();
void testOrderedDynamicStructString();
void testDynamicStructInt();