Changeset 258828 in webkit


Ignore:
Timestamp:
Mar 23, 2020 2:48:12 AM (4 years ago)
Author:
youenn@apple.com
Message:

StringView::startsWith and String::startsWith do not treat null strings the same
https://bugs.webkit.org/show_bug.cgi?id=209273

Reviewed by Darin Adler.

Source/WTF:

Align StringImpl with StringView and make startsWith return true if prefix is null.

  • wtf/text/StringImpl.cpp:

(WTF::StringImpl::startsWith const):

Tools:

  • TestWebKitAPI/Tests/WTF/StringView.cpp:

(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WTF/WTFString.cpp:

(TestWebKitAPI::TEST):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r258826 r258828  
     12020-03-23  youenn fablet  <youenn@apple.com>
     2
     3        StringView::startsWith and String::startsWith do not treat null strings the same
     4        https://bugs.webkit.org/show_bug.cgi?id=209273
     5
     6        Reviewed by Darin Adler.
     7
     8        Align StringImpl with StringView and make startsWith return true if prefix is null.
     9
     10        * wtf/text/StringImpl.cpp:
     11        (WTF::StringImpl::startsWith const):
     12
    1132020-03-22  Antoine Quint  <graouts@apple.com>
    214
  • trunk/Source/WTF/wtf/text/StringImpl.cpp

    r255125 r258828  
    11841184bool StringImpl::startsWith(const StringImpl* string) const
    11851185{
    1186     return string && ::WTF::startsWith(*this, *string);
     1186    return !string || ::WTF::startsWith(*this, *string);
    11871187}
    11881188
  • trunk/Tools/ChangeLog

    r258826 r258828  
     12020-03-23  youenn fablet  <youenn@apple.com>
     2
     3        StringView::startsWith and String::startsWith do not treat null strings the same
     4        https://bugs.webkit.org/show_bug.cgi?id=209273
     5
     6        Reviewed by Darin Adler.
     7
     8        * TestWebKitAPI/Tests/WTF/StringView.cpp:
     9        (TestWebKitAPI::TEST):
     10        * TestWebKitAPI/Tests/WTF/WTFString.cpp:
     11        (TestWebKitAPI::TEST):
     12
    1132020-03-22  Antoine Quint  <graouts@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp

    r251736 r258828  
    4242}
    4343
     44TEST(WTF, StringViewStartsWithEmptyVsNull)
     45{
     46    StringView nullView;
     47    StringView emptyView = StringView::empty();
     48    String stringWithCharacters("hello");
     49    StringView viewWithCharacters(stringWithCharacters);
     50
     51    EXPECT_TRUE(viewWithCharacters.startsWith(nullView));
     52    EXPECT_TRUE(viewWithCharacters.startsWith(emptyView));
     53}
     54
    4455TEST(WTF, StringViewEmptyVsNull)
    4556{
  • trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp

    r250389 r258828  
    7272}
    7373
     74TEST(WTF, StringStartsWithEmptyVsNull)
     75{
     76    String nullString;
     77    String emptyString = WTF::emptyString();
     78    String stringWithCharacters("hello");
     79
     80    EXPECT_TRUE(stringWithCharacters.startsWith(nullString));
     81    EXPECT_TRUE(stringWithCharacters.startsWith(emptyString));
     82}
     83
    7484static inline const char* testStringNumberFixedPrecision(double number)
    7585{
Note: See TracChangeset for help on using the changeset viewer.