Changeset 252813 in webkit


Ignore:
Timestamp:
Nov 22, 2019 4:04:05 PM (4 years ago)
Author:
Chris Dumez
Message:

HTTPHeaderMap's operator== is not fully correct
https://bugs.webkit.org/show_bug.cgi?id=204361

Reviewed by Alex Christensen.

Source/WebCore:

If headers are added in a different order, HTTPHeaderMap's operator==() would wrongly
return false because it is using a Vector internally to store the headers. Also, it
would incorrectly return false if the case of the headers did not match.

  • platform/network/HTTPHeaderMap.cpp:

(WebCore::HTTPHeaderMap::get const):
(WebCore::HTTPHeaderMap::getUncommonHeader const):

  • platform/network/HTTPHeaderMap.h:

(WebCore::HTTPHeaderMap::operator==):

Tools:

Add API test coverage.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebCore/HTTPHeaderMap.cpp: Added.

(TestWebKitAPI::TEST):

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252810 r252813  
     12019-11-22  Chris Dumez  <cdumez@apple.com>
     2
     3        HTTPHeaderMap's operator== is not fully correct
     4        https://bugs.webkit.org/show_bug.cgi?id=204361
     5
     6        Reviewed by Alex Christensen.
     7
     8        If headers are added in a different order, HTTPHeaderMap's operator==() would wrongly
     9        return false because it is using a Vector internally to store the headers. Also, it
     10        would incorrectly return false if the case of the headers did not match.
     11
     12        * platform/network/HTTPHeaderMap.cpp:
     13        (WebCore::HTTPHeaderMap::get const):
     14        (WebCore::HTTPHeaderMap::getUncommonHeader const):
     15        * platform/network/HTTPHeaderMap.h:
     16        (WebCore::HTTPHeaderMap::operator==):
     17
    1182019-11-22  Zalan Bujtas  <zalan@apple.com>
    219
  • trunk/Source/WebCore/platform/network/HTTPHeaderMap.cpp

    r248316 r252813  
    5656        return get(headerName);
    5757
     58    return getUncommonHeader(name);
     59}
     60
     61String HTTPHeaderMap::getUncommonHeader(const String& name) const
     62{
    5863    auto index = m_uncommonHeaders.findMatching([&](auto& header) {
    5964        return equalIgnoringASCIICase(header.key, name);
  • trunk/Source/WebCore/platform/network/HTTPHeaderMap.h

    r248316 r252813  
    159159    WEBCORE_EXPORT void append(const String& name, const String& value);
    160160    WEBCORE_EXPORT bool contains(const String&) const;
    161     bool remove(const String&);
     161    WEBCORE_EXPORT bool remove(const String&);
    162162
    163163#if USE(CF)
     
    191191    friend bool operator==(const HTTPHeaderMap& a, const HTTPHeaderMap& b)
    192192    {
    193         return a.m_commonHeaders == b.m_commonHeaders && a.m_uncommonHeaders == b.m_uncommonHeaders;
     193        if (a.m_commonHeaders.size() != b.m_commonHeaders.size() || a.m_uncommonHeaders.size() != b.m_uncommonHeaders.size())
     194            return false;
     195        for (auto& commonHeader : a.m_commonHeaders) {
     196            if (b.get(commonHeader.key) != commonHeader.value)
     197                return false;
     198        }
     199        for (auto& uncommonHeader : a.m_uncommonHeaders) {
     200            if (b.getUncommonHeader(uncommonHeader.key) != uncommonHeader.value)
     201                return false;
     202        }
     203        return true;
    194204    }
    195205
     
    204214private:
    205215    void setUncommonHeader(const String& name, const String& value);
     216    WEBCORE_EXPORT String getUncommonHeader(const String& name) const;
    206217
    207218    CommonHeadersVector m_commonHeaders;
  • trunk/Tools/ChangeLog

    r252805 r252813  
     12019-11-22  Chris Dumez  <cdumez@apple.com>
     2
     3        HTTPHeaderMap's operator== is not fully correct
     4        https://bugs.webkit.org/show_bug.cgi?id=204361
     5
     6        Reviewed by Alex Christensen.
     7
     8        Add API test coverage.
     9
     10        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     11        * TestWebKitAPI/Tests/WebCore/HTTPHeaderMap.cpp: Added.
     12        (TestWebKitAPI::TEST):
     13
    1142019-11-22  Sihui Liu  <sihui_liu@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r252805 r252813  
    247247                46E816F81E79E29C00375ADC /* RestoreStateAfterTermination.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46E816F71E79E29100375ADC /* RestoreStateAfterTermination.mm */; };
    248248                46EBD8472372320F00223A6E /* RestoreScrollPosition.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46EBD846237231E600223A6E /* RestoreScrollPosition.mm */; };
     249                46FA2FEE23846CA5000CCB0C /* HTTPHeaderMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46FA2FED23846C9A000CCB0C /* HTTPHeaderMap.cpp */; };
    249250                4909EE3A2D09480C88982D56 /* Markable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC79F168BE454E579E417B05 /* Markable.cpp */; };
    250251                4BFDFFA71314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */; };
     
    17791780                46E816F71E79E29100375ADC /* RestoreStateAfterTermination.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RestoreStateAfterTermination.mm; sourceTree = "<group>"; };
    17801781                46EBD846237231E600223A6E /* RestoreScrollPosition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RestoreScrollPosition.mm; sourceTree = "<group>"; };
     1782                46FA2FED23846C9A000CCB0C /* HTTPHeaderMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPHeaderMap.cpp; sourceTree = "<group>"; };
    17811783                4A410F4B19AF7BD6002EBAB5 /* UserMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserMedia.cpp; sourceTree = "<group>"; };
    17821784                4A410F4D19AF7BEF002EBAB5 /* getUserMedia.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = getUserMedia.html; sourceTree = "<group>"; };
     
    31043106                                83B88A331C80056D00BB2418 /* HTMLParserIdioms.cpp */,
    31053107                                5CA1DEC71F71F40700E71BD3 /* HTTPHeaderField.cpp */,
     3108                                46FA2FED23846C9A000CCB0C /* HTTPHeaderMap.cpp */,
    31063109                                6B9ABE112086952F00D75DE6 /* HTTPParsers.cpp */,
    31073110                                7A909A731D877475007E10F8 /* IntPoint.cpp */,
     
    46684671                                7C83E0501D0A641800FEBCF3 /* HTMLParserIdioms.cpp in Sources */,
    46694672                                5CA1DEC81F71F70100E71BD3 /* HTTPHeaderField.cpp in Sources */,
     4673                                46FA2FEE23846CA5000CCB0C /* HTTPHeaderMap.cpp in Sources */,
    46704674                                6B9ABE122086952F00D75DE6 /* HTTPParsers.cpp in Sources */,
    46714675                                5C7C24FC237C975400599C91 /* HTTPServer.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.