Skip to content

Commit

Permalink
Fix json_relaxed::arrayFromStream
Browse files Browse the repository at this point in the history
  • Loading branch information
asuch authored and vogel76 committed Nov 2, 2023
1 parent 68bcf93 commit 936247b
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions libraries/fc/include/fc/io/json_relaxed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,26 +627,40 @@ namespace fc { namespace json_relaxed
{
if( in.peek() != '[' )
FC_THROW_EXCEPTION( parse_error_exception, "Expected '['" );

in.get();
skip_white_space( in, depth );
bool expecting_new_element = true;

while( in.peek() != ']' )
{
if( in.peek() == ',' )
{
if (ar.empty())
FC_THROW_EXCEPTION( parse_error_exception, "Invalid leading comma.");
if (expecting_new_element)
FC_THROW_EXCEPTION( parse_error_exception, "Found invalid comma instead of new array element.");

in.get();
expecting_new_element = true;
continue;
}
if( skip_white_space( in, depth ) ) continue;
if( skip_white_space( in, depth ) )
continue;
if (!expecting_new_element)
FC_THROW_EXCEPTION( parse_error_exception, "Missing ',' after object in json array.");

ar.push_back( json_relaxed::variant_from_stream<T, strict>( in, depth ) );
expecting_new_element = false;
skip_white_space( in, depth );
}
if( in.peek() != ']' )
FC_THROW_EXCEPTION( parse_error_exception, "Expected ']' after parsing ${variant}",
("variant", ar) );

if (expecting_new_element && !ar.empty())
FC_THROW_EXCEPTION( parse_error_exception, "Detected ',' after last array object. Expected ']'");

in.get();
} FC_RETHROW_EXCEPTIONS( warn, "Attempting to parse array ${array}",
}
FC_RETHROW_EXCEPTIONS( warn, "Attempting to parse array ${array}",
("array", ar ) );
return ar;
}
Expand Down

0 comments on commit 936247b

Please sign in to comment.