Skip to content

Commit

Permalink
fix parse_into handling of tuple of the wrong size
Browse files Browse the repository at this point in the history
  • Loading branch information
grisumbras committed Oct 7, 2024
1 parent b036074 commit 27c40ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/boost/json/detail/parse_into.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ class converting_handler<tuple_conversion_tag, T, P>
if( inner_active_ < N )
{
BOOST_JSON_FAIL( ec, error::size_mismatch );
return true;
return false;
}

inner_active_ = -1;
Expand Down
14 changes: 12 additions & 2 deletions test/parse_into.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,17 @@ class parse_into_test
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
system::error_code ec;
T t{};
T t1{};
std::string json = serialize(sample);
parser_for<T> p( parse_options{}, &t );

parse_into<T>(t1, json, ec);
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST( ec == e );

T t2{};
ec = {};
parser_for<T> p( parse_options{}, &t2 );
for( auto& c: json )
{
std::size_t const n = p.write_some( true, &c, 1, ec );
Expand Down Expand Up @@ -355,6 +363,8 @@ class parse_into_test
error::size_mismatch, {1, 2} );
testParseIntoErrors< std::tuple<std::vector<int>> >(
error::size_mismatch, {{1,2}, {3,4}} );
testParseIntoErrors<std::map<std::string, std::tuple<int, int>>>(
error::size_mismatch, { {"tup", array()} });
}

void testStruct()
Expand Down

0 comments on commit 27c40ee

Please sign in to comment.