diff --git a/include/boost/json/detail/value_to.hpp b/include/boost/json/detail/value_to.hpp index 66c3858c7..5e50dc6ce 100644 --- a/include/boost/json/detail/value_to.hpp +++ b/include/boost/json/detail/value_to.hpp @@ -461,7 +461,7 @@ value_to_impl( return {system::in_place_error, ec}; } - if( !describe::enum_from_string(str->data(), val) ) + if( !describe::enum_from_string(str->subview(), val) ) { BOOST_JSON_FAIL(ec, error::unknown_name); return {system::in_place_error, ec}; diff --git a/test/value_to.cpp b/test/value_to.cpp index 2906d8649..97712f365 100644 --- a/test/value_to.cpp +++ b/test/value_to.cpp @@ -496,6 +496,14 @@ class value_to_test BOOST_TEST_THROWS_WITH_LOCATION( value_to<::value_to_test_ns::E1>( value("x"), ctx... )); + { + // an embedded null must not truncate the enumerator name + value const jv( string_view("a\0", 2) ); + BOOST_TEST( jv.as_string().size() == 2 ); + BOOST_TEST_THROWS_WITH_LOCATION( + value_to<::value_to_test_ns::E1>( jv, ctx... )); + } + { #ifndef BOOST_NO_CXX17_HDR_OPTIONAL value jv = {{"n", -78}, {"d", 0.125}};