Skip to content

Commit

Permalink
field verification uses internal linkage
Browse files Browse the repository at this point in the history
  • Loading branch information
cmazakas committed Feb 9, 2024
1 parent 00ebd90 commit c3f5073
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
30 changes: 13 additions & 17 deletions src/fields_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <boost/assert.hpp>
#include <boost/assert/source_location.hpp>

#include <boost/core/detail/string_view.hpp>

#include <boost/system/result.hpp>

#include <boost/url/grammar/ci_string.hpp>
Expand All @@ -34,27 +36,25 @@
namespace boost {
namespace http_proto {

system::result<typename detail::field_name_rule_t::value_type>
static
system::result<core::string_view>
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<typename detail::field_value_rule_t::value_type>
verify_field_value(
core::string_view value)
Expand All @@ -70,8 +70,7 @@ verify_field_value(
return rv.error();

Check warning on line 70 in src/fields_base.cpp

View check run for this annotation

Codecov / codecov/patch

src/fields_base.cpp#L70

Added line #L70 was not covered by tests
}

auto v = rv.value();
if( v.has_crlf )
if( rv->has_crlf )
return error::bad_field_smuggle;

if( it != end )
Expand Down Expand Up @@ -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 {};
}

Expand Down
7 changes: 4 additions & 3 deletions test/unit/fields_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,10 @@ struct fields_base_test
BOOST_TEST(rv.has_error());
BOOST_TEST(rv.error() == error::bad_field_name);

std::vector<char const *> strs = {"\r\nABC", "\rABC", "A\rBC",
"ABC\r", "\nABC", "A\nBC",
"ABC\n", "\r", "\n"};
std::vector<char const *> strs = {
"\r\nABC", "\rABC", "A\rBC",
"ABC\r", "\nABC", "A\nBC",
"ABC\n", "\r", "\n"};

for (auto const str : strs)
{
Expand Down

0 comments on commit c3f5073

Please sign in to comment.