From 792940166d427a6a9eae91090c02cdfb84f5106f Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Tue, 18 Mar 2025 20:09:47 +1300 Subject: [PATCH] LibWeb/LibURL: Use an IgnoreCase enum for URLPatternOptions This is to save a future name conflict that will appear between the options IDL dictionary and the options struct that are both present in the spec. It is also a nicer interface for now given there is only a single option at the moment. --- Libraries/LibURL/Pattern/Pattern.cpp | 2 +- Libraries/LibURL/Pattern/Pattern.h | 13 +++++++------ Libraries/LibWeb/URLPattern/URLPattern.cpp | 2 +- Libraries/LibWeb/URLPattern/URLPattern.h | 6 +++++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Libraries/LibURL/Pattern/Pattern.cpp b/Libraries/LibURL/Pattern/Pattern.cpp index 7cb256d03df..f8b60441cd6 100644 --- a/Libraries/LibURL/Pattern/Pattern.cpp +++ b/Libraries/LibURL/Pattern/Pattern.cpp @@ -10,7 +10,7 @@ namespace URL::Pattern { // https://urlpattern.spec.whatwg.org/#url-pattern-create -PatternErrorOr Pattern::create(Input const& input, Optional const& base_url, Options const&) +PatternErrorOr Pattern::create(Input const& input, Optional const& base_url, IgnoreCase) { // 1. Let init be null. Init init; diff --git a/Libraries/LibURL/Pattern/Pattern.h b/Libraries/LibURL/Pattern/Pattern.h index c540b9985a5..e2b1bb59ea6 100644 --- a/Libraries/LibURL/Pattern/Pattern.h +++ b/Libraries/LibURL/Pattern/Pattern.h @@ -19,11 +19,6 @@ namespace URL::Pattern { // https://urlpattern.spec.whatwg.org/#typedefdef-urlpatterninput using Input = Variant; -// https://urlpattern.spec.whatwg.org/#dictdef-urlpatternoptions -struct Options { - bool ignore_case { false }; -}; - // https://urlpattern.spec.whatwg.org/#dictdef-urlpatterncomponentresult struct ComponentResult { String input; @@ -44,10 +39,16 @@ struct Result { ComponentResult hash; }; +// https://urlpattern.spec.whatwg.org/#dictdef-urlpatternoptions +enum class IgnoreCase { + Yes, + No, +}; + // https://urlpattern.spec.whatwg.org/#url-pattern class Pattern { public: - static PatternErrorOr create(Input const&, Optional const& base_url = {}, Options const& = {}); + static PatternErrorOr create(Input const&, Optional const& base_url = {}, IgnoreCase = IgnoreCase::No); PatternErrorOr> match(Input const&, Optional const& base_url_string) const; diff --git a/Libraries/LibWeb/URLPattern/URLPattern.cpp b/Libraries/LibWeb/URLPattern/URLPattern.cpp index 42a70ffbecb..9521e87ab51 100644 --- a/Libraries/LibWeb/URLPattern/URLPattern.cpp +++ b/Libraries/LibWeb/URLPattern/URLPattern.cpp @@ -45,7 +45,7 @@ WebIDL::ExceptionOr> URLPattern::construct_impl(JS::Realm& r WebIDL::ExceptionOr> URLPattern::create(JS::Realm& realm, URLPatternInput const& input, Optional const& base_url, URLPatternOptions const& options) { // 1. Set this’s associated URL pattern to the result of create given input, baseURL, and options. - auto pattern_or_error = URL::Pattern::Pattern::create(input, base_url, options); + auto pattern_or_error = URL::Pattern::Pattern::create(input, base_url, options.ignore_case ? URL::Pattern::IgnoreCase::Yes : URL::Pattern::IgnoreCase::No); if (pattern_or_error.is_error()) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, pattern_or_error.error().message }; return realm.create(realm, pattern_or_error.release_value()); diff --git a/Libraries/LibWeb/URLPattern/URLPattern.h b/Libraries/LibWeb/URLPattern/URLPattern.h index 87821c18e4b..03a58ce4c5c 100644 --- a/Libraries/LibWeb/URLPattern/URLPattern.h +++ b/Libraries/LibWeb/URLPattern/URLPattern.h @@ -15,9 +15,13 @@ namespace Web::URLPattern { using URLPatternInit = URL::Pattern::Init; using URLPatternInput = URL::Pattern::Input; -using URLPatternOptions = URL::Pattern::Options; using URLPatternResult = URL::Pattern::Result; +// https://urlpattern.spec.whatwg.org/#dictdef-urlpatternoptions +struct URLPatternOptions { + bool ignore_case { false }; +}; + // https://urlpattern.spec.whatwg.org/#urlpattern class URLPattern : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(URLPattern, Bindings::PlatformObject);