fixed: when reading a non-escaped space token we should check whether a delimiter was escaped or not

also a '#' was not tested
This commit is contained in:
Tomasz Sowa 2021-03-18 16:26:56 +01:00
parent db5e516564
commit 4119461f8e
2 changed files with 9 additions and 6 deletions

View File

@ -674,7 +674,7 @@ protected:
if( !is_main_object ) if( !is_main_object )
{ {
str << '{'; str << '{';
print_if(pretty_print, str, '\n'); print_if(pretty_print && (!value.value_object.empty() || (child_spaces && !child_spaces->empty())), str, '\n');
} }
bool is_first = true; bool is_first = true;

View File

@ -739,7 +739,7 @@ void SpaceParser::SkipWhite()
{ {
if( parsing_space ) if( parsing_space )
{ {
while( IsWhite(lastc) || lastc == '#' ) while( IsWhite(lastc) || (!char_was_escaped && lastc == '#') )
{ {
if( lastc == '#' ) if( lastc == '#' )
SkipLine(); SkipLine();
@ -808,7 +808,7 @@ void SpaceParser::ReadTokenUntilDelimiter(std::wstring & token, int delimiter1,
{ {
token.clear(); token.clear();
while( lastc != -1 && lastc != '\n' && lastc != '#' && lastc != delimiter1 && lastc != delimiter2 ) while( lastc != -1 && (char_was_escaped || (lastc != '\n' && lastc != '#' && lastc != delimiter1 && lastc != delimiter2)) )
{ {
token += static_cast<wchar_t>(lastc); token += static_cast<wchar_t>(lastc);
ReadChar(); ReadChar();
@ -860,7 +860,7 @@ void SpaceParser::ReadSpaceFieldToken(std::wstring & token)
{ {
token.clear(); token.clear();
while( lastc != -1 && (char_was_escaped || (lastc != separator && lastc != 10 && lastc != space_start)) ) while( lastc != -1 && (char_was_escaped || (lastc != separator && lastc != 10 && lastc != space_start && lastc != '#' )) )
{ {
token += static_cast<wchar_t>(lastc); token += static_cast<wchar_t>(lastc);
ReadChar(); ReadChar();
@ -915,7 +915,10 @@ void SpaceParser::ReadMultilineTokenQuoted(std::wstring & token)
} }
/*
* this method is used to read the field name (key) in an object
* or to read the space child name (used in Space format)
*/
void SpaceParser::ReadKey() void SpaceParser::ReadKey()
{ {
SkipWhite(); SkipWhite();
@ -1128,7 +1131,7 @@ int SpaceParser::ReadChar()
case 'b': lastc = 0x08; break; case 'b': lastc = 0x08; break;
case 'f': lastc = 0x0c; break; case 'f': lastc = 0x0c; break;
case 'u': ReadUnicodeCodePoint(); break; case 'u': ReadUnicodeCodePoint(); break;
// in other cases we return the last character // "in other cases we return the last character, so two \\ returns one \ "
} }
} }