Changeset 233660 in webkit


Ignore:
Timestamp:
Jul 9, 2018 3:30:40 PM (6 years ago)
Author:
youenn@apple.com
Message:

StringView operator==(char*) should check the length of the string
https://bugs.webkit.org/show_bug.cgi?id=187422

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

  • web-platform-tests/eventsource/format-field-parsing-expected.txt:

Source/WebCore:

Covered by existing tests.

  • Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:

(WebCore::IDBServer::SQLiteIDBBackingStore::databaseNameFromEncodedFilename):

Source/WTF:

Update StringView operator== to ensure that any character raw pointer comparison actually check the length of the raw pointer string.
This patch mimicks the behavior of String.
For instance, comparing a StringView with "he\0llo" and "he" will give the same result.

  • wtf/linux/MemoryFootprintLinux.cpp:

(WTF::memoryFootprint):

  • wtf/text/StringView.h:

(WTF::operator==):
(WTF::operator!=):
(WTF::equal):
(WTF::StringView::stripLeadingAndTrailingMatchedCharacters):

Tools:

  • TestWebKitAPI/Tests/WTF/StringView.cpp:

(TestWebKitAPI::equal2):
(TestWebKitAPI::TEST):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r233632 r233660  
     12018-07-09  Youenn Fablet  <youenn@apple.com>
     2
     3        StringView operator==(char*) should check the length of the string
     4        https://bugs.webkit.org/show_bug.cgi?id=187422
     5
     6        Reviewed by Chris Dumez.
     7
     8        * web-platform-tests/eventsource/format-field-parsing-expected.txt:
     9
    1102018-07-08  Antoine Quint  <graouts@apple.com>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/eventsource/format-field-parsing-expected.txt

    r220733 r233660  
    11
    2 FAIL EventSource: field parsing assert_equals: expected "\0\n 2\n1\n3\n\n4" but got "\0\n 2\n2\n1\n3\n\n4"
     2PASS EventSource: field parsing
    33
  • trunk/Source/WTF/ChangeLog

    r233646 r233660  
     12018-07-09  Youenn Fablet  <youenn@apple.com>
     2
     3        StringView operator==(char*) should check the length of the string
     4        https://bugs.webkit.org/show_bug.cgi?id=187422
     5
     6        Reviewed by Chris Dumez.
     7
     8        Update StringView operator== to ensure that any character raw pointer comparison actually check the length of the raw pointer string.
     9        This patch mimicks the behavior of String.
     10        For instance, comparing a StringView with "he\0llo" and "he" will give the same result.
     11
     12        * wtf/linux/MemoryFootprintLinux.cpp:
     13        (WTF::memoryFootprint):
     14        * wtf/text/StringView.h:
     15        (WTF::operator==):
     16        (WTF::operator!=):
     17        (WTF::equal):
     18        (WTF::StringView::stripLeadingAndTrailingMatchedCharacters):
     19
    1202018-07-09  Yusuke Suzuki  <utatane.tea@gmail.com>
    221
  • trunk/Source/WTF/wtf/linux/MemoryFootprintLinux.cpp

    r233420 r233660  
    7373            if (scannedCount == 7) {
    7474                StringView pathString(path);
    75                 isAnonymous = pathString == "[heap]"_s || pathString.startsWith("[stack");
     75                isAnonymous = pathString == "[heap]" | pathString.startsWith("[stack");
    7676                return;
    7777            }
  • trunk/Source/WTF/wtf/text/StringView.h

    r232302 r233660  
    194194
    195195bool equal(StringView, StringView);
    196 bool equal(StringView, const LChar*);
    197 bool equal(StringView, const char*);
     196bool equal(StringView, const LChar* b);
    198197
    199198bool equalIgnoringASCIICase(StringView, StringView);
     
    203202
    204203inline bool operator==(StringView a, StringView b) { return equal(a, b); }
    205 inline bool operator==(StringView a, const LChar* b) { return equal(a, b); }
    206 inline bool operator==(StringView a, const char* b) { return equal(a, b); }
    207 inline bool operator==(const LChar* a, StringView b) { return equal(b, a); }
     204inline bool operator==(StringView a, const LChar *b);
     205inline bool operator==(StringView a, const char *b) { return equal(a, reinterpret_cast<const LChar*>(b)); }
    208206inline bool operator==(const char* a, StringView b) { return equal(b, a); }
    209207
     
    211209inline bool operator!=(StringView a, const LChar* b) { return !equal(a, b); }
    212210inline bool operator!=(StringView a, const char* b) { return !equal(a, b); }
    213 inline bool operator!=(const LChar* a, StringView b) { return !equal(b, a); }
    214 inline bool operator!=(const char* a, StringView b) { return !equal(b, a); }
     211inline bool operator!=(const LChar*a, StringView b) { return !equal(b, a); }
     212inline bool operator!=(const char*a, StringView b) { return !equal(b, a); }
    215213
    216214}
     
    606604        return a.length() == b.length();
    607605    }
    608        
     606
    609607    return equalCommon(a, b);
    610608}
     
    616614    if (a.isEmpty())
    617615        return !b;
     616
    618617    unsigned aLength = a.length();
     618    if (aLength != strlen(reinterpret_cast<const char*>(b)))
     619        return false;
     620
    619621    if (a.is8Bit())
    620622        return equal(a.characters8(), b, aLength);
    621623    return equal(a.characters16(), b, aLength);
    622 }
    623 
    624 inline bool equal(StringView a, const char* b)
    625 {
    626     return equal(a, reinterpret_cast<const LChar*>(b));
    627624}
    628625
     
    957954    unsigned start = 0;
    958955    unsigned end = m_length - 1;
    959    
     956
    960957    while (start <= end && predicate(characters[start]))
    961958        ++start;
    962    
     959
    963960    if (start > end)
    964961        return StringView::empty();
  • trunk/Source/WebCore/ChangeLog

    r233652 r233660  
     12018-07-09  Youenn Fablet  <youenn@apple.com>
     2
     3        StringView operator==(char*) should check the length of the string
     4        https://bugs.webkit.org/show_bug.cgi?id=187422
     5
     6        Reviewed by Chris Dumez.
     7
     8        Covered by existing tests.
     9
     10        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
     11        (WebCore::IDBServer::SQLiteIDBBackingStore::databaseNameFromEncodedFilename):
     12
    1132018-07-09  Simon Fraser  <simon.fraser@apple.com>
    214
  • trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp

    r233122 r233660  
    738738String SQLiteIDBBackingStore::databaseNameFromEncodedFilename(const String& encodedName)
    739739{
    740     if (equal(encodedName, "%00"_s))
     740    if (encodedName == "%00"_s)
    741741        return { };
    742742
  • trunk/Tools/ChangeLog

    r233651 r233660  
     12018-07-09  Youenn Fablet  <youenn@apple.com>
     2
     3        StringView operator==(char*) should check the length of the string
     4        https://bugs.webkit.org/show_bug.cgi?id=187422
     5
     6        Reviewed by Chris Dumez.
     7
     8        * TestWebKitAPI/Tests/WTF/StringView.cpp:
     9        (TestWebKitAPI::equal2):
     10        (TestWebKitAPI::TEST):
     11
    1122018-07-09  Ross Kirsling  <rkirsling@gmail.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp

    r220982 r233660  
    299299}
    300300
     301TEST(WTF, StringViewEqualBasic)
     302{
     303    String referenceHolder;
     304    StringView a = stringViewFromUTF8(referenceHolder, "Hello World!");
     305    EXPECT_TRUE(a == "Hello World!");
     306    EXPECT_FALSE(a == "Hello World");
     307    EXPECT_FALSE(a == "Hello World!!");
     308
     309    auto test = "Hell\0";
     310    a = StringView { (const LChar*)test, 5 };
     311    EXPECT_FALSE(a == "Hell\0");
     312    EXPECT_FALSE(a == "Hell");
     313
     314    StringView test3 = "Hello";
     315    EXPECT_TRUE(test3 == "Hello\0");
     316    EXPECT_TRUE(test3 == "Hello");
     317}
     318
    301319TEST(WTF, StringViewEqualIgnoringASCIICaseBasic)
    302320{
Note: See TracChangeset for help on using the changeset viewer.