Changeset 205188 in webkit
- Timestamp:
- Aug 30, 2016 11:09:07 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r205169 r205188 1 2016-08-30 Youenn Fablet <youenn@apple.com> 2 3 [Fetch API] Body mix-in text() should decode data as UTF-8 4 https://bugs.webkit.org/show_bug.cgi?id=161372 5 6 Reviewed by Sam Weinig. 7 8 * web-platform-tests/fetch/api/basic/text-utf8-expected.txt: Added. 9 * web-platform-tests/fetch/api/basic/text-utf8.html: Added. 10 * web-platform-tests/fetch/api/resources/status.py: Added. 11 (main): 12 1 13 2016-08-29 Chris Dumez <cdumez@apple.com> 2 14 -
trunk/Source/WebCore/ChangeLog
r205186 r205188 1 2016-08-30 Youenn Fablet <youenn@apple.com> 2 3 [Fetch API] Body mix-in text() should decode data as UTF-8 4 https://bugs.webkit.org/show_bug.cgi?id=161372 5 6 Reviewed by Sam Weinig. 7 8 Test: imported/w3c/web-platform-tests/fetch/api/basic/text-utf8.html 9 10 UsingTextResourceDecoder to decode data as UTF-8. 11 Making sure to prepend BOM if there is none, as specified in https://encoding.spec.whatwg.org/#utf-8-decode. 12 13 * Modules/fetch/FetchBodyConsumer.cpp: 14 (WebCore::shouldPrependBOM): 15 (WebCore::textFromUTF8): 16 (WebCore::FetchBodyConsumer::resolveWithData): 17 (WebCore::FetchBodyConsumer::takeAsText): 18 1 19 2016-08-30 Zalan Bujtas <zalan@apple.com> 2 20 -
trunk/Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp
r204171 r205188 34 34 #include "JSBlob.h" 35 35 #include "JSDOMPromise.h" 36 #include "TextResourceDecoder.h" 36 37 37 38 namespace WebCore { … … 42 43 memcpy(value.data(), data, length); 43 44 return Blob::create(WTFMove(value), contentType); 45 } 46 47 static inline bool shouldPrependBOM(const unsigned char* data, unsigned length) 48 { 49 if (length < 3) 50 return true; 51 return data[0] != 0xef || data[1] != 0xbb || data[2] != 0xbf; 52 } 53 54 static String textFromUTF8(const unsigned char* data, unsigned length) 55 { 56 auto decoder = TextResourceDecoder::create("text/plain", "UTF-8"); 57 if (shouldPrependBOM(data, length)) 58 decoder->decode("\xef\xbb\xbf", 3); 59 return decoder->decodeAndFlush(reinterpret_cast<const char*>(data), length); 44 60 } 45 61 … … 54 70 return; 55 71 case Type::JSON: 56 fulfillPromiseWithJSON(promise, String(data, length));72 fulfillPromiseWithJSON(promise, textFromUTF8(data, length)); 57 73 return; 58 74 case Type::Text: 59 promise.resolve( String(data, length));75 promise.resolve(textFromUTF8(data, length)); 60 76 return; 61 77 case Type::None: … … 127 143 String FetchBodyConsumer::takeAsText() 128 144 { 145 // FIXME: We could probably text decode on the fly as soon as m_type is set to JSON or Text. 129 146 if (!m_buffer) 130 147 return String(); 131 148 132 auto text = String(m_buffer->data(), m_buffer->size());149 auto text = textFromUTF8(reinterpret_cast<const unsigned char*>(m_buffer->data()), m_buffer->size()); 133 150 m_buffer = nullptr; 134 151 return text;
Note: See TracChangeset
for help on using the changeset viewer.