Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Source/udJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,13 @@ udResult udJSON::Parse(const char *pString, int *pCharCount, int *pLineNumber)
}
else if (*pString == '\"' || *pString == '\'') // Allow single quotes
{
size_t endPos = udStrMatchBrace(pString, '\\');
size_t endPos;
if (pCharCount)
endPos = udStrMatchBrace(pString, '\\');
else
endPos = udStrlen(pString);
while (pString[endPos - 1] == ' ' || pString[endPos - 1] == '\t')
--endPos;
// Force a parse error if the string isn't quoted properly
UD_ERROR_IF(pString[endPos - 1] != pString[0], udR_ParseError);
char *pStr = udAllocType(char, endPos, udAF_None);
Expand Down
8 changes: 8 additions & 0 deletions udTest/src/udJSONTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ TEST(udJSONTests, CreationSimple)
g_udBreakOnError = false;
EXPECT_NE(udR_Success, v.Set("Settings.Something"));
g_udBreakOnError = true;

EXPECT_EQ(udR_Success, v.Set("Settings.MyString1 = 'has ' quote'")); // Literals accept quote character mid-string as a special case
EXPECT_EQ(udR_Success, v.Set("Settings.MyString2 = 'has \\' quote'")); // Quote character escaped
EXPECT_EQ(0, udStrcmp(v.Get("Settings.MyString1").AsString(), v.Get("Settings.MyString2").AsString()));
EXPECT_EQ(udR_Success, v.Set("Settings.MyString3 = \"has \\\" quote\" ")); // Test with double-quote character and trailing spaces
EXPECT_EQ(udR_Success, v.Set("Settings.MyString4 = 'has \" quote' ")); // Test with double-quote character and trailing spaces
EXPECT_EQ(0, udStrcmp(v.Get("Settings.MyString3").AsString(), v.Get("Settings.MyString4").AsString()));

EXPECT_EQ(udR_Success, v.Set("Settings.EmptyArray = []"));
EXPECT_EQ(udR_Success, v.Set("Settings.Nothing = null"));
// Of note here is that the input string is currently JSON escaped, so there's some additional backslashes
Expand Down