Title: [206636] trunk
Revision
206636
Author
[email protected]
Date
2016-09-30 09:08:30 -0700 (Fri, 30 Sep 2016)

Log Message

FetchBody should use UTF8Encoding to encode text data
https://bugs.webkit.org/show_bug.cgi?id=162775

Patch by Youenn Fablet <[email protected]> on 2016-09-30
Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

* web-platform-tests/fetch/api/basic/text-utf8-expected.txt:
* web-platform-tests/fetch/api/basic/text-utf8.html:
* web-platform-tests/fetch/api/resources/utils.js:
(encode_utf8):

Source/WebCore:

Covered by added tests.

Removing unnecesary vector allocation when extracting UTF8 bytes from a Request/Response text/URLSearchParams body.
Making use of UTF8Encoding for consistency with  the upload code path.

* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::consumeAsStream):
(WebCore::FetchBody::consumeText):
(WebCore::extractBytesFromText): Deleted.

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (206635 => 206636)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-09-30 16:01:36 UTC (rev 206635)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-09-30 16:08:30 UTC (rev 206636)
@@ -1,3 +1,15 @@
+2016-09-30  Youenn Fablet  <[email protected]>
+
+        FetchBody should use UTF8Encoding to encode text data
+        https://bugs.webkit.org/show_bug.cgi?id=162775
+
+        Reviewed by Sam Weinig.
+
+        * web-platform-tests/fetch/api/basic/text-utf8-expected.txt:
+        * web-platform-tests/fetch/api/basic/text-utf8.html:
+        * web-platform-tests/fetch/api/resources/utils.js:
+        (encode_utf8):
+
 2016-09-30  Chris Dumez  <[email protected]>
 
         Add support for ImageData.data attribute

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/text-utf8-expected.txt (206635 => 206636)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/text-utf8-expected.txt	2016-09-30 16:01:36 UTC (rev 206635)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/text-utf8-expected.txt	2016-09-30 16:08:30 UTC (rev 206636)
@@ -3,20 +3,30 @@
 PASS UTF-8 with BOM with Response.text() 
 PASS UTF-8 with BOM with fetched data (UTF-8 charset) 
 PASS UTF-8 with BOM with fetched data (UTF-16 charset) 
+PASS UTF-8 with BOM (Response object) 
+PASS UTF-8 with BOM (Request object) 
 PASS UTF-8 without BOM with Request.text() 
 PASS UTF-8 without BOM with Response.text() 
 PASS UTF-8 without BOM with fetched data (UTF-8 charset) 
 PASS UTF-8 without BOM with fetched data (UTF-16 charset) 
+PASS UTF-8 without BOM (Response object) 
+PASS UTF-8 without BOM (Request object) 
 PASS UTF-16BE with BOM decoded as UTF-8 with Request.text() 
 PASS UTF-16BE with BOM decoded as UTF-8 with Response.text() 
 PASS UTF-16BE with BOM decoded as UTF-8 with fetched data (UTF-8 charset) 
 PASS UTF-16BE with BOM decoded as UTF-8 with fetched data (UTF-16 charset) 
+PASS UTF-16BE with BOM decoded as UTF-8 (Response object) 
+PASS UTF-16BE with BOM decoded as UTF-8 (Request object) 
 PASS UTF-16LE with BOM decoded as UTF-8 with Request.text() 
 PASS UTF-16LE with BOM decoded as UTF-8 with Response.text() 
 PASS UTF-16LE with BOM decoded as UTF-8 with fetched data (UTF-8 charset) 
 PASS UTF-16LE with BOM decoded as UTF-8 with fetched data (UTF-16 charset) 
+PASS UTF-16LE with BOM decoded as UTF-8 (Response object) 
+PASS UTF-16LE with BOM decoded as UTF-8 (Request object) 
 PASS UTF-16 without BOM decoded as UTF-8 with Request.text() 
 PASS UTF-16 without BOM decoded as UTF-8 with Response.text() 
 PASS UTF-16 without BOM decoded as UTF-8 with fetched data (UTF-8 charset) 
 PASS UTF-16 without BOM decoded as UTF-8 with fetched data (UTF-16 charset) 
+PASS UTF-16 without BOM decoded as UTF-8 (Response object) 
+PASS UTF-16 without BOM decoded as UTF-8 (Request object) 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/text-utf8.html (206635 => 206636)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/text-utf8.html	2016-09-30 16:01:36 UTC (rev 206635)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/text-utf8.html	2016-09-30 16:08:30 UTC (rev 206636)
@@ -41,6 +41,19 @@
             });
         });
     }, title + " with fetched data (UTF-16 charset)");
+
+    promise_test(function(test) {
+        return new Response(body).arrayBuffer().then(function(buffer) {
+            validateBufferFromString(buffer, encode_utf8(body), "Response.arrayBuffer() should contain data encoded as UTF-8");
+        });
+    }, title + " (Response object)");
+
+    promise_test(function(test) {
+        return new Request("", {method: "POST", body: body}).arrayBuffer().then(function(buffer) {
+            validateBufferFromString(buffer, encode_utf8(body), "Request.arrayBuffer() should contain data encoded as UTF-8");
+        });
+    }, title + " (Request object)");
+
 }
 
 var utf8WithBOM = "\xef\xbb\xbf\xe4\xb8\x89\xe6\x9d\x91\xe3\x81\x8b\xe3\x81\xaa\xe5\xad\x90";

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/utils.js (206635 => 206636)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/utils.js	2016-09-30 16:01:36 UTC (rev 206635)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/utils.js	2016-09-30 16:08:30 UTC (rev 206636)
@@ -44,6 +44,11 @@
   }
 }
 
+function encode_utf8(str)
+{
+    return unescape(encodeURIComponent(str));
+}
+
 function stringToArray(str) {
   var array = new Uint8Array(str.length);
   for (var i=0, strLen = str.length; i < strLen; i++)

Modified: trunk/Source/WebCore/ChangeLog (206635 => 206636)


--- trunk/Source/WebCore/ChangeLog	2016-09-30 16:01:36 UTC (rev 206635)
+++ trunk/Source/WebCore/ChangeLog	2016-09-30 16:08:30 UTC (rev 206636)
@@ -1,3 +1,20 @@
+2016-09-30  Youenn Fablet  <[email protected]>
+
+        FetchBody should use UTF8Encoding to encode text data
+        https://bugs.webkit.org/show_bug.cgi?id=162775
+
+        Reviewed by Sam Weinig.
+
+        Covered by added tests.
+
+        Removing unnecesary vector allocation when extracting UTF8 bytes from a Request/Response text/URLSearchParams body.
+        Making use of UTF8Encoding for consistency with  the upload code path.
+
+        * Modules/fetch/FetchBody.cpp:
+        (WebCore::FetchBody::consumeAsStream):
+        (WebCore::FetchBody::consumeText):
+        (WebCore::extractBytesFromText): Deleted.
+
 2016-09-30  Said Abou-Hallawa  <[email protected]>
 
         Change the MemoryCache and CachedResource adjustSize functions to take a long argument

Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.cpp (206635 => 206636)


--- trunk/Source/WebCore/Modules/fetch/FetchBody.cpp	2016-09-30 16:01:36 UTC (rev 206635)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.cpp	2016-09-30 16:08:30 UTC (rev 206636)
@@ -47,15 +47,6 @@
 
 namespace WebCore {
 
-// FIXME: This implementation is not efficient and we should probably use UTF8Encoding().
-static Vector<uint8_t> extractBytesFromText(const String& text)
-{
-    CString data = ""
-    Vector<uint8_t> value(data.length());
-    memcpy(value.data(), data.data(), data.length());
-    return value;
-}
-
 FetchBody::FetchBody(Ref<const Blob>&& blob)
     : m_type(Type::Blob)
     , m_data(WTFMove(blob))
@@ -247,14 +238,14 @@
         break;
     }
     case Type::Text: {
-        Vector<uint8_t> data = ""
-        closeStream = source.enqueue(ArrayBuffer::tryCreate(data.data(), data.size()));
+        auto data = "" EntitiesForUnencodables);
+        closeStream = source.enqueue(ArrayBuffer::tryCreate(data.data(), data.length()));
         m_data = nullptr;
         break;
     }
     case Type::URLSeachParams: {
-        Vector<uint8_t> data = ""
-        closeStream = source.enqueue(ArrayBuffer::tryCreate(data.data(), data.size()));
+        auto data = "" EntitiesForUnencodables);
+        closeStream = source.enqueue(ArrayBuffer::tryCreate(data.data(), data.length()));
         m_data = nullptr;
         break;
     }
@@ -292,8 +283,8 @@
 
 void FetchBody::consumeText(Ref<DeferredPromise>&& promise, const String& text)
 {
-    Vector<uint8_t> data = ""
-    m_consumer.resolveWithData(WTFMove(promise), data.data(), data.size());
+    auto data = "" EntitiesForUnencodables);
+    m_consumer.resolveWithData(WTFMove(promise), reinterpret_cast<const uint8_t*>(data.data()), data.length());
     m_data = nullptr;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to