Browse Source

LibWeb: Implement CaseInsensitiveBytesTraits::equals()

Turns out HashTable::contains() doesn't solely use hash() for equality
checks, so the lack of a proper equals() implementation broke the check
in convert_header_names_to_a_sorted_lowercase_set() and caused duplicate
entries in header_names_set.
Linus Groh 3 years ago
parent
commit
bad6ad8861
1 changed files with 6 additions and 1 deletions
  1. 6 1
      Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp

+ 6 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp

@@ -20,7 +20,12 @@ namespace Web::Fetch::Infrastructure {
 
 
 template<typename T>
 template<typename T>
 requires(IsSameIgnoringCV<T, u8>) struct CaseInsensitiveBytesTraits : public Traits<Span<T>> {
 requires(IsSameIgnoringCV<T, u8>) struct CaseInsensitiveBytesTraits : public Traits<Span<T>> {
-    static unsigned hash(Span<T> const& span)
+    static constexpr bool equals(Span<T> const& a, Span<T> const& b)
+    {
+        return StringView { a }.equals_ignoring_case(StringView { b });
+    }
+
+    static constexpr unsigned hash(Span<T> const& span)
     {
     {
         if (span.is_empty())
         if (span.is_empty())
             return 0;
             return 0;