From 911abb33427d87b8b8e5f63eba574704c05aa998 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 23 Sep 2025 20:52:23 -0400 Subject: [PATCH 1/2] simplify process methods in url pattern --- src/url_pattern.cpp | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/url_pattern.cpp b/src/url_pattern.cpp index 6168be863..c806e74db 100644 --- a/src/url_pattern.cpp +++ b/src/url_pattern.cpp @@ -261,13 +261,13 @@ tl::expected url_pattern_init::process( tl::expected url_pattern_init::process_protocol( std::string_view value, process_type type) { ada_log("process_protocol=", value, " [", type, "]"); - // Let strippedValue be the given value with a single trailing U+003A (:) - // removed, if any. - if (value.ends_with(":")) { - value.remove_suffix(1); - } // If type is "pattern" then return strippedValue. if (type == process_type::pattern) { + // Let strippedValue be the given value with a single trailing U+003A (:) + // removed, if any. + if (value.ends_with(":")) { + value.remove_suffix(1); + } return std::string(value); } // Return the result of running canonicalize a protocol given strippedValue. @@ -336,18 +336,17 @@ tl::expected url_pattern_init::process_pathname( tl::expected url_pattern_init::process_search( std::string_view value, process_type type) { - // Let strippedValue be the given value with a single leading U+003F (?) - // removed, if any. - if (value.starts_with("?")) { - value.remove_prefix(1); - } - // We cannot assert that the value is no longer starting with a single - // question mark because technically it can start. The question is whether or - // not we should remove the first question mark. Ref: - // https://github.com/ada-url/ada/pull/992 The spec is not clear on this. - // If type is "pattern" then return strippedValue. if (type == process_type::pattern) { + // Let strippedValue be the given value with a single leading U+003F (?) + // removed, if any. + if (value.starts_with("?")) { + value.remove_prefix(1); + } + // We cannot assert that the value is no longer starting with a single + // question mark because technically it can start. The question is whether + // or not we should remove the first question mark. Ref: + // https://github.com/ada-url/ada/pull/992 The spec is not clear on this. return std::string(value); } // Return the result of running canonicalize a search given strippedValue. @@ -356,14 +355,13 @@ tl::expected url_pattern_init::process_search( tl::expected url_pattern_init::process_hash( std::string_view value, process_type type) { - // Let strippedValue be the given value with a single leading U+0023 (#) - // removed, if any. - if (value.starts_with("#")) { - value.remove_prefix(1); - } - ADA_ASSERT_TRUE(!value.starts_with("#")); // If type is "pattern" then return strippedValue. if (type == process_type::pattern) { + // Let strippedValue be the given value with a single leading U+0023 (#) + // removed, if any. + if (value.starts_with("#")) { + value.remove_prefix(1); + } return std::string(value); } // Return the result of running canonicalize a hash given strippedValue. From 2a4a26532655141bb7373dad356d63a7b93fa6d9 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 23 Sep 2025 21:01:32 -0400 Subject: [PATCH 2/2] increase fuzzing coverage on urlpattern --- fuzz/url_pattern.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/fuzz/url_pattern.cc b/fuzz/url_pattern.cc index 271a41142..5a63ba4b4 100644 --- a/fuzz/url_pattern.cc +++ b/fuzz/url_pattern.cc @@ -97,7 +97,22 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { } auto result_with_init = ada::parse_url_pattern( init, &base_source_view, nullptr); - if (result_with_init) exercise_result(*result_with_init); + if (result_with_init) { + exercise_result(*result_with_init); + } + + ada::url_pattern_init hostname_init{}; + hostname_init.hostname = "*"; + auto valid_urlpattern = + ada::parse_url_pattern(hostname_init, nullptr, nullptr); + std::string_view valid_input = + "https://www.yagiz.co/???this-is-my-search#####this-is-hash"; + (void)valid_urlpattern->exec(valid_input, nullptr); + (void)valid_urlpattern->exec(valid_input, &base_source_view); + (void)valid_urlpattern->exec(base_source_view, nullptr); + (void)valid_urlpattern->test(valid_input, nullptr); + (void)valid_urlpattern->test(valid_input, &base_source_view); + (void)valid_urlpattern->test(base_source_view, nullptr); } return 0;