Title: [233660] trunk
Revision
233660
Author
[email protected]
Date
2018-07-09 15:30:40 -0700 (Mon, 09 Jul 2018)

Log 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):

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (233659 => 233660)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2018-07-09 21:56:51 UTC (rev 233659)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2018-07-09 22:30:40 UTC (rev 233660)
@@ -1,3 +1,12 @@
+2018-07-09  Youenn Fablet  <[email protected]>
+
+        StringView operator==(char*) should check the length of the string
+        https://bugs.webkit.org/show_bug.cgi?id=187422
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/eventsource/format-field-parsing-expected.txt:
+
 2018-07-08  Antoine Quint  <[email protected]>
 
         [Web Animations] A number of tests report an incorrect computed offset

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/eventsource/format-field-parsing-expected.txt (233659 => 233660)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/eventsource/format-field-parsing-expected.txt	2018-07-09 21:56:51 UTC (rev 233659)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/eventsource/format-field-parsing-expected.txt	2018-07-09 22:30:40 UTC (rev 233660)
@@ -1,3 +1,3 @@
 
-FAIL EventSource: field parsing assert_equals: expected "\0\n 2\n1\n3\n\n4" but got "\0\n 2\n2\n1\n3\n\n4"
+PASS EventSource: field parsing 
 

Modified: trunk/Source/WTF/ChangeLog (233659 => 233660)


--- trunk/Source/WTF/ChangeLog	2018-07-09 21:56:51 UTC (rev 233659)
+++ trunk/Source/WTF/ChangeLog	2018-07-09 22:30:40 UTC (rev 233660)
@@ -1,3 +1,22 @@
+2018-07-09  Youenn Fablet  <[email protected]>
+
+        StringView operator==(char*) should check the length of the string
+        https://bugs.webkit.org/show_bug.cgi?id=187422
+
+        Reviewed by Chris Dumez.
+
+        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):
+
 2018-07-09  Yusuke Suzuki  <[email protected]>
 
         [WTF] Annotate RunLoop::Timer fast-allocated

Modified: trunk/Source/WTF/wtf/linux/MemoryFootprintLinux.cpp (233659 => 233660)


--- trunk/Source/WTF/wtf/linux/MemoryFootprintLinux.cpp	2018-07-09 21:56:51 UTC (rev 233659)
+++ trunk/Source/WTF/wtf/linux/MemoryFootprintLinux.cpp	2018-07-09 22:30:40 UTC (rev 233660)
@@ -72,7 +72,7 @@
             }
             if (scannedCount == 7) {
                 StringView pathString(path);
-                isAnonymous = pathString == "[heap]"_s || pathString.startsWith("[stack");
+                isAnonymous = pathString == "[heap]" | pathString.startsWith("[stack");
                 return;
             }
         }

Modified: trunk/Source/WTF/wtf/text/StringView.h (233659 => 233660)


--- trunk/Source/WTF/wtf/text/StringView.h	2018-07-09 21:56:51 UTC (rev 233659)
+++ trunk/Source/WTF/wtf/text/StringView.h	2018-07-09 22:30:40 UTC (rev 233660)
@@ -193,8 +193,7 @@
 template<typename CharacterType, size_t inlineCapacity> void append(Vector<CharacterType, inlineCapacity>&, StringView);
 
 bool equal(StringView, StringView);
-bool equal(StringView, const LChar*);
-bool equal(StringView, const char*);
+bool equal(StringView, const LChar* b);
 
 bool equalIgnoringASCIICase(StringView, StringView);
 bool equalIgnoringASCIICase(StringView, const char*);
@@ -202,16 +201,15 @@
 template<unsigned length> bool equalLettersIgnoringASCIICase(StringView, const char (&lowercaseLetters)[length]);
 
 inline bool operator==(StringView a, StringView b) { return equal(a, b); }
-inline bool operator==(StringView a, const LChar* b) { return equal(a, b); }
-inline bool operator==(StringView a, const char* b) { return equal(a, b); }
-inline bool operator==(const LChar* a, StringView b) { return equal(b, a); }
+inline bool operator==(StringView a, const LChar *b);
+inline bool operator==(StringView a, const char *b) { return equal(a, reinterpret_cast<const LChar*>(b)); }
 inline bool operator==(const char* a, StringView b) { return equal(b, a); }
 
 inline bool operator!=(StringView a, StringView b) { return !equal(a, b); }
 inline bool operator!=(StringView a, const LChar* b) { return !equal(a, b); }
 inline bool operator!=(StringView a, const char* b) { return !equal(a, b); }
-inline bool operator!=(const LChar* a, StringView b) { return !equal(b, a); }
-inline bool operator!=(const char* a, StringView b) { return !equal(b, a); }
+inline bool operator!=(const LChar*a, StringView b) { return !equal(b, a); }
+inline bool operator!=(const char*a, StringView b) { return !equal(b, a); }
 
 }
 
@@ -605,7 +603,7 @@
         ASSERT(a.is8Bit() == b.is8Bit());
         return a.length() == b.length();
     }
-        
+
     return equalCommon(a, b);
 }
 
@@ -615,17 +613,16 @@
         return !a.isEmpty();
     if (a.isEmpty())
         return !b;
+
     unsigned aLength = a.length();
+    if (aLength != strlen(reinterpret_cast<const char*>(b)))
+        return false;
+
     if (a.is8Bit())
         return equal(a.characters8(), b, aLength);
     return equal(a.characters16(), b, aLength);
 }
 
-inline bool equal(StringView a, const char* b) 
-{
-    return equal(a, reinterpret_cast<const LChar*>(b)); 
-}
-
 inline bool equalIgnoringASCIICase(StringView a, StringView b)
 {
     return equalIgnoringASCIICaseCommon(a, b);
@@ -956,10 +953,10 @@
 
     unsigned start = 0;
     unsigned end = m_length - 1;
-    
+
     while (start <= end && predicate(characters[start]))
         ++start;
-    
+
     if (start > end)
         return StringView::empty();
 

Modified: trunk/Source/WebCore/ChangeLog (233659 => 233660)


--- trunk/Source/WebCore/ChangeLog	2018-07-09 21:56:51 UTC (rev 233659)
+++ trunk/Source/WebCore/ChangeLog	2018-07-09 22:30:40 UTC (rev 233660)
@@ -1,3 +1,15 @@
+2018-07-09  Youenn Fablet  <[email protected]>
+
+        StringView operator==(char*) should check the length of the string
+        https://bugs.webkit.org/show_bug.cgi?id=187422
+
+        Reviewed by Chris Dumez.
+
+        Covered by existing tests.
+
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
+        (WebCore::IDBServer::SQLiteIDBBackingStore::databaseNameFromEncodedFilename):
+
 2018-07-09  Simon Fraser  <[email protected]>
 
         Shrink WebCore::Pair

Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp (233659 => 233660)


--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp	2018-07-09 21:56:51 UTC (rev 233659)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp	2018-07-09 22:30:40 UTC (rev 233660)
@@ -737,7 +737,7 @@
 
 String SQLiteIDBBackingStore::databaseNameFromEncodedFilename(const String& encodedName)
 {
-    if (equal(encodedName, "%00"_s))
+    if (encodedName == "%00"_s)
         return { };
 
     String partiallyDecoded = encodedName;

Modified: trunk/Tools/ChangeLog (233659 => 233660)


--- trunk/Tools/ChangeLog	2018-07-09 21:56:51 UTC (rev 233659)
+++ trunk/Tools/ChangeLog	2018-07-09 22:30:40 UTC (rev 233660)
@@ -1,3 +1,14 @@
+2018-07-09  Youenn Fablet  <[email protected]>
+
+        StringView operator==(char*) should check the length of the string
+        https://bugs.webkit.org/show_bug.cgi?id=187422
+
+        Reviewed by Chris Dumez.
+
+        * TestWebKitAPI/Tests/WTF/StringView.cpp:
+        (TestWebKitAPI::equal2):
+        (TestWebKitAPI::TEST):
+
 2018-07-09  Ross Kirsling  <[email protected]>
 
         [WinCairo] httpd service install needs to precede server start

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp (233659 => 233660)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp	2018-07-09 21:56:51 UTC (rev 233659)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp	2018-07-09 22:30:40 UTC (rev 233660)
@@ -298,6 +298,24 @@
         EXPECT_STREQ(expected[i].utf8().data(), actual[i].utf8().data()) << "Vectors differ at index " << i;
 }
 
+TEST(WTF, StringViewEqualBasic)
+{
+    String referenceHolder;
+    StringView a = stringViewFromUTF8(referenceHolder, "Hello World!");
+    EXPECT_TRUE(a == "Hello World!");
+    EXPECT_FALSE(a == "Hello World");
+    EXPECT_FALSE(a == "Hello World!!");
+
+    auto test = "Hell\0";
+    a = StringView { (const LChar*)test, 5 };
+    EXPECT_FALSE(a == "Hell\0");
+    EXPECT_FALSE(a == "Hell");
+
+    StringView test3 = "Hello";
+    EXPECT_TRUE(test3 == "Hello\0");
+    EXPECT_TRUE(test3 == "Hello");
+}
+
 TEST(WTF, StringViewEqualIgnoringASCIICaseBasic)
 {
     RefPtr<StringImpl> a = StringImpl::createFromLiteral("aBcDeFG");
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to