From c3f50734961df57650373fe722751317cc7a78a8 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Thu, 8 Feb 2024 10:32:10 -0800 Subject: [PATCH] field verification uses internal linkage --- src/fields_base.cpp | 30 +++++++++++++----------------- test/unit/fields_base.cpp | 7 ++++--- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/fields_base.cpp b/src/fields_base.cpp index aabfc300..5aeb03b1 100644 --- a/src/fields_base.cpp +++ b/src/fields_base.cpp @@ -21,6 +21,8 @@ #include #include +#include + #include #include @@ -34,27 +36,25 @@ namespace boost { namespace http_proto { -system::result +static +system::result verify_field_name( core::string_view name) { - auto it = name.begin(); - auto end = name.end(); auto rv = - grammar::parse(it, end, detail::field_name_rule); + grammar::parse(name, detail::field_name_rule); if( rv.has_error() ) { - if( rv.error() == condition::need_more_input ) + auto ec = rv.error(); + if( ec == urls::grammar::error::leftover ) + return error::bad_field_name; + if( ec == condition::need_more_input ) return error::bad_field_name; - return rv.error(); } - - if( it != end ) - return error::bad_field_name; - - return rv.value(); + return rv; } +static system::result verify_field_value( core::string_view value) @@ -70,8 +70,7 @@ verify_field_value( return rv.error(); } - auto v = rv.value(); - if( v.has_crlf ) + if( rv->has_crlf ) return error::bad_field_smuggle; if( it != end ) @@ -880,11 +879,8 @@ insert_impl( if( rv.has_error() ) return rv.error(); - value = rv->value; - bool has_obs_fold = rv->has_obs_fold; insert_impl_unchecked( - id, name, value, before, has_obs_fold); - + id, name, rv->value, before, rv->has_obs_fold); return {}; } diff --git a/test/unit/fields_base.cpp b/test/unit/fields_base.cpp index eca22a52..bbec9f11 100644 --- a/test/unit/fields_base.cpp +++ b/test/unit/fields_base.cpp @@ -462,9 +462,10 @@ struct fields_base_test BOOST_TEST(rv.has_error()); BOOST_TEST(rv.error() == error::bad_field_name); - std::vector strs = {"\r\nABC", "\rABC", "A\rBC", - "ABC\r", "\nABC", "A\nBC", - "ABC\n", "\r", "\n"}; + std::vector strs = { + "\r\nABC", "\rABC", "A\rBC", + "ABC\r", "\nABC", "A\nBC", + "ABC\n", "\r", "\n"}; for (auto const str : strs) {