From 07899933fbeacb0259d4d488d9eb189a1b287976 Mon Sep 17 00:00:00 2001 From: Ramya Eliger Date: Sun, 27 Sep 2026 02:01:19 +0530 Subject: [PATCH] pass full string_view to enum_from_string in value_to --- include/boost/json/detail/value_to.hpp | 2 +- test/value_to.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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}};