<commit_before>#include "source/common/http/path_utility.h"

#include "test/common/http/path_utility_fuzz.pb.validate.h"
#include "test/fuzz/fuzz_runner.h"
#include "test/fuzz/utility.h"

namespace Envoy {
namespace Fuzz {
namespace {
DEFINE_PROTO_FUZZER(const test::common::http::PathUtilityTestCase& input) {
  try {
    TestUtility::validate(input);
  } catch (const ProtoValidationException& e) {
    ENVOY_LOG_MISC(debug, "ProtoValidationException: {}", e.what());
    return;
  }

  switch (input.path_utility_selector_case()) {
  case test::common::http::PathUtilityTestCase::kCanonicalPath: {
    auto request_headers = fromHeaders<Http::TestRequestHeaderMapImpl>(
        input.canonical_path().request_headers(), {},
        {":path"}); // needs to have path header in order to be valid
    Http::PathUtil::canonicalPath(request_headers);
    ASSERT(!request_headers.getPathValue().empty());
    break;
  }
  case test::common::http::PathUtilityTestCase::kMergeSlashes: {
    auto request_headers = fromHeaders<Http::TestRequestHeaderMapImpl>(
        input.merge_slashes().request_headers(), {}, {":path"});
    Http::PathUtil::mergeSlashes(request_headers);
    break;
  }
  case test::common::http::PathUtilityTestCase::kRemoveQueryAndFragment: {
    auto path = input.remove_query_and_fragment().path();<commit_msg>[fuzz] Path utility fuzzer logging (#19358)<commit_after>#include "source/common/http/path_utility.h"

#include "test/common/http/path_utility_fuzz.pb.validate.h"
#include "test/fuzz/fuzz_runner.h"
#include "test/fuzz/utility.h"

namespace Envoy {
namespace Fuzz {
namespace {
DEFINE_PROTO_FUZZER(const test::common::http::PathUtilityTestCase& input) {
  try {
    TestUtility::validate(input);
  } catch (const ProtoValidationException& e) {
    ENVOY_LOG_MISC(debug, "ProtoValidationException: {}", e.what());
    return;
  }

  // The following log is needed to pass the `check_build` tests of
  // Cluster-Fuzz for empty inputs.
  ENVOY_LOG_MISC(trace, "Input: {}", input.DebugString());

  switch (input.path_utility_selector_case()) {
  case test::common::http::PathUtilityTestCase::kCanonicalPath: {
    auto request_headers = fromHeaders<Http::TestRequestHeaderMapImpl>(
        input.canonical_path().request_headers(), {},
        {":path"}); // needs to have path header in order to be valid
    Http::PathUtil::canonicalPath(request_headers);
    ASSERT(!request_headers.getPathValue().empty());
    break;
  }
  case test::common::http::PathUtilityTestCase::kMergeSlashes: {
    auto request_headers = fromHeaders<Http::TestRequestHeaderMapImpl>(
        input.merge_slashes().request_headers(), {}, {":path"});
    Http::PathUtil::mergeSlashes(request_headers);
    break;
  }
  case test::common::http::PathUtilityTestCase::kRemoveQueryAndFragment: {
    auto path = input.remove_query_and_fragment().path();
{'fraction_non_alphanumeric': 0.1423562412342216, 'fraction_numerical': 0.0017531556802244039, 'mean_word_length': 5.498861047835991, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4361999', 'n_tokens_mistral': 898, 'n_tokens_neox': 889, 'n_words': 146}