Important Update:

- JSONparse:
  - Allow base entry to be Array or Object
  - Do not enforce escaping of '/' -> '\/'
  - Bug fix: properly encode string values in arrays
This commit is contained in:
Charl Wentzel
2019-07-16 16:43:55 +02:00
parent c682fd6504
commit fb28f86ae9

View File

@@ -352,11 +352,11 @@ bool CJSONparse::ReadFromBuffer( const char * BasePath )
// Parse Root Object
SkipWhiteSpace();
if (!ParseObject( BaseMember )) {
if (!ParseObject( BaseMember ) && !Error && !ParseArray( BaseMember )) {
if (!Error) {
Error = true;
CharNo += BufPos-Mark;
sprintf( ErrorText, "First entry in file must be an Object on line %d:%d", LineNo, CharNo );
sprintf( ErrorText, "First entry in file must be an Object or Array on line %d:%d", LineNo, CharNo );
}
FreeBuffer();
return false;
@@ -475,7 +475,7 @@ bool CJSONparse::ParseString( char ** Value, int &Len )
while (true)
{
// Check for special characters
if ((EndMark = strpbrk( BufPos, "\"/\\\n\t\b\f\n\r" ))) {
if ((EndMark = strpbrk( BufPos, "\"\\\n\t\b\f\n\r" ))) { /*"\"/\\\n\t\b\f\n\r" (forward slash included)*/
BufPos = EndMark;
} else if (RefillBuffer) {
FillBuffer();
@@ -816,7 +816,7 @@ bool CJSONparse::PrintString( char * String, int Len )
{
// Scan for special chars
Mark = BufPos;
while ((*BufPos >= 32) && (*BufPos <= 126) && (*BufPos != '\\') && (*BufPos != '/') && (*BufPos != '"'))
while ((*BufPos >= 32) && (*BufPos <= 126) && (*BufPos != '\\') && /*(*BufPos != '/') &&*/ (*BufPos != '"'))
BufPos++;
// Print Portion
@@ -1029,9 +1029,7 @@ bool CJSONparse::PrintArray( CDataMember * Array, const int Indent )
break;
case jtString :
if ((Print( this, "\"", 1 ) < 0) ||
(Print( this, Member->Value, Member->Len ) < 0) ||
(Print( this, "\"", 1 ) < 0))
if (!PrintString( Member->Value, Member->Len ))
return false;
break;