Modern IDB: Some tests crash with specific odd database names.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Jan 2016 22:25:21 +0000 (22:25 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Jan 2016 22:25:21 +0000 (22:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=153688

Reviewed by Darin Adler.

Source/WebCore:

No new tests (2 existing tests now pass).

* platform/FileSystem.cpp:
(WebCore::shouldEscapeUChar): Return true for some surrogate-pair situations.
(WebCore::encodeForFileName): Pass along the previous and next characters, as well,
  and do a two byte escaping for some characters.

LayoutTests:

* platform/mac-wk1/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@195913 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/mac-wk1/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/platform/FileSystem.cpp

index 352b8a5..ad09cad 100644 (file)
@@ -1,3 +1,12 @@
+2016-01-30  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Some tests crash with specific odd database names.
+        https://bugs.webkit.org/show_bug.cgi?id=153688
+
+        Reviewed by Darin Adler.
+
+        * platform/mac-wk1/TestExpectations:
+
 2016-01-30  Eric Carlson  <eric.carlson@apple.com>
 
         More than one audio and/or text track sometimes selected in media controls menu
index a86d751..3be4ea1 100644 (file)
@@ -271,9 +271,7 @@ storage/indexeddb/prefetch-invalidation.html [ Skip ]
 storage/indexeddb/transaction-coordination-within-database.html [ Skip ]
 
 # SQLite backend tests that crash or ASSERT
-storage/indexeddb/database-odd-names.html [ Skip ]
 storage/indexeddb/dont-wedge.html [ Skip ]
-storage/indexeddb/odd-strings.html [ Skip ]
 
 ### END OF (3) IndexedDB failures with SQLite
 ########################################
index 8ac94c7..53f10d8 100644 (file)
@@ -1,3 +1,17 @@
+2016-01-30  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Some tests crash with specific odd database names.
+        https://bugs.webkit.org/show_bug.cgi?id=153688
+
+        Reviewed by Darin Adler.
+
+        No new tests (2 existing tests now pass).
+
+        * platform/FileSystem.cpp:
+        (WebCore::shouldEscapeUChar): Return true for some surrogate-pair situations.
+        (WebCore::encodeForFileName): Pass along the previous and next characters, as well,
+          and do a two byte escaping for some characters.
+
 2016-01-30  Eric Carlson  <eric.carlson@apple.com>
 
         More than one audio and/or text track sometimes selected in media controls menu
index 87e3053..2b5397a 100644 (file)
@@ -82,21 +82,46 @@ static const bool needsEscaping[128] = {
     /* 78-7F */ false, false, false, false, true,  false, false, true, 
 };
 
-static inline bool shouldEscapeUChar(UChar c)
+static inline bool shouldEscapeUChar(UChar character, UChar previousCharacter, UChar nextCharacter)
 {
-    return c > 127 ? false : needsEscaping[c];
+    if (character <= 127)
+        return needsEscaping[character];
+
+    if (U16_IS_LEAD(character) && !U16_IS_TRAIL(nextCharacter))
+        return true;
+
+    if (U16_IS_TRAIL(character) && !U16_IS_LEAD(previousCharacter))
+        return true;
+
+    return false;
 }
 
 String encodeForFileName(const String& inputString)
 {
-    StringBuilder result;
-    StringImpl* stringImpl = inputString.impl();
     unsigned length = inputString.length();
+    if (!length)
+        return inputString;
+
+    StringBuilder result;
+    result.reserveCapacity(length);
+
+    UChar previousCharacter;
+    UChar character = 0;
+    UChar nextCharacter = inputString[0];
     for (unsigned i = 0; i < length; ++i) {
-        UChar character = (*stringImpl)[i];
-        if (shouldEscapeUChar(character)) {
-            result.append('%');
-            appendByteAsHex(character, result);
+        previousCharacter = character;
+        character = nextCharacter;
+        nextCharacter = i + 1 < length ? inputString[i + 1] : 0;
+
+        if (shouldEscapeUChar(character, previousCharacter, nextCharacter)) {
+            if (character <= 255) {
+                result.append('%');
+                appendByteAsHex(character, result);
+            } else {
+                result.appendLiteral("%+");
+                appendByteAsHex(character >> 8, result);
+                appendByteAsHex(character, result);
+            }
         } else
             result.append(character);
     }