WebKit Bugzilla
Attachment 356588 Details for
Bug 182325
: Align with Fetch on data: URLs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-182325-20181205092150.patch (text/plain), 9.22 KB, created by
Rob Buis
on 2018-12-05 00:21:51 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Rob Buis
Created:
2018-12-05 00:21:51 PST
Size:
9.22 KB
patch
obsolete
>Subversion Revision: 238854 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index d85b8dac7d0fc41a6c106843784721cd6e154864..7ad89a501c19e6d742610190dd1bae596a2c7329 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,27 @@ >+2018-12-04 Rob Buis <rbuis@igalia.com> >+ >+ Align with Fetch on data: URLs >+ https://bugs.webkit.org/show_bug.cgi?id=182325 >+ >+ Reviewed by Alex Christensen. >+ >+ Do not accept data URLs that do not contain a comma >+ character, as specified in the relevant specs [1, 2]. >+ >+ Behavior matches Firefox and Chrome. >+ >+ Test: web-platform-tests/fetch/api/basic/scheme-data.any.html >+ >+ [1] https://tools.ietf.org/html/rfc2397 >+ [2] https://fetch.spec.whatwg.org/#data-url-processor >+ >+ * platform/network/DataURLDecoder.cpp: >+ (WebCore::DataURLDecoder::parseMediaType): >+ (WebCore::DataURLDecoder::DecodeTask::DecodeTask): >+ (WebCore::DataURLDecoder::DecodeTask::process): >+ (WebCore::DataURLDecoder::createDecodeTask): >+ (WebCore::DataURLDecoder::decode): >+ > 2018-12-04 Carlos Garcia Campos <cgarcia@igalia.com> > > [SOUP] Move URLSoup back to WebCore after r238771 >diff --git a/Source/WebCore/platform/network/DataURLDecoder.cpp b/Source/WebCore/platform/network/DataURLDecoder.cpp >index 4605bea0a7a16d13a5d2c0e906fbae90cdd4622c..59ddf074a5f32c50a1b76cd10dec88bcac851de7 100644 >--- a/Source/WebCore/platform/network/DataURLDecoder.cpp >+++ b/Source/WebCore/platform/network/DataURLDecoder.cpp >@@ -45,22 +45,56 @@ static WorkQueue& decodeQueue() > return queue; > } > >+static Result parseMediaType(const String& mediaType) >+{ >+ auto mimeType = extractMIMETypeFromMediaType(mediaType); >+ auto charset = extractCharsetFromMediaType(mediaType); >+ >+ // https://tools.ietf.org/html/rfc2397 >+ // If <mediatype> is omitted, it defaults to text/plain;charset=US-ASCII. As a shorthand, >+ // "text/plain" can be omitted but the charset parameter supplied. >+ if (mimeType.isEmpty()) { >+ mimeType = "text/plain"_s; >+ if (charset.isEmpty()) >+ charset = "US-ASCII"_s; >+ } >+ return { mimeType, charset, !mediaType.isEmpty() ? mediaType : "text/plain;charset=US-ASCII", nullptr }; >+} >+ > struct DecodeTask { > WTF_MAKE_FAST_ALLOCATED; > public: >- DecodeTask(const String& urlString, StringView&& encodedData, bool isBase64, const ScheduleContext& scheduleContext, DecodeCompletionHandler&& completionHandler, Result&& result) >+ DecodeTask(const String& urlString, const ScheduleContext& scheduleContext, DecodeCompletionHandler&& completionHandler) > : urlString(urlString.isolatedCopy()) >- , encodedData(WTFMove(encodedData)) >- , isBase64(isBase64) > , scheduleContext(scheduleContext) > , completionHandler(WTFMove(completionHandler)) >- , result(WTFMove(result)) > { > } > >+ bool process() >+ { >+ if (urlString.find(',') == notFound) >+ return false; >+ const char dataString[] = "data:"; >+ const char base64String[] = ";base64"; >+ >+ ASSERT(urlString.startsWith(dataString)); >+ >+ size_t headerEnd = urlString.find(',', strlen(dataString)); >+ size_t encodedDataStart = headerEnd == notFound ? headerEnd : headerEnd + 1; >+ >+ encodedData = StringView(urlString).substring(encodedDataStart); >+ auto header = StringView(urlString).substring(strlen(dataString), headerEnd - strlen(dataString)); >+ isBase64 = header.endsWithIgnoringASCIICase(StringView(base64String)); >+ auto mediaType = (isBase64 ? header.substring(0, header.length() - strlen(base64String)) : header).toString(); >+ result = parseMediaType(mediaType); >+ >+ return true; >+ } >+ > const String urlString; >- const StringView encodedData; >- const bool isBase64; >+ StringView encodedData; >+ bool isBase64 { false }; > const ScheduleContext scheduleContext; > const DecodeCompletionHandler completionHandler; > >@@ -113,45 +147,12 @@ private: > > #endif // HAVE(RUNLOOP_TIMER) > >-static Result parseMediaType(const String& mediaType) >-{ >- auto mimeType = extractMIMETypeFromMediaType(mediaType); >- auto charset = extractCharsetFromMediaType(mediaType); >- >- // https://tools.ietf.org/html/rfc2397 >- // If <mediatype> is omitted, it defaults to text/plain;charset=US-ASCII. As a shorthand, >- // "text/plain" can be omitted but the charset parameter supplied. >- if (mimeType.isEmpty()) { >- mimeType = "text/plain"_s; >- if (charset.isEmpty()) >- charset = "US-ASCII"_s; >- } >- return { mimeType, charset, !mediaType.isEmpty() ? mediaType : "text/plain;charset=US-ASCII", nullptr }; >-} >- > static std::unique_ptr<DecodeTask> createDecodeTask(const URL& url, const ScheduleContext& scheduleContext, DecodeCompletionHandler&& completionHandler) > { >- const char dataString[] = "data:"; >- const char base64String[] = ";base64"; >- >- auto urlString = url.string(); >- ASSERT(urlString.startsWith(dataString)); >- >- size_t headerEnd = urlString.find(',', strlen(dataString)); >- size_t encodedDataStart = headerEnd == notFound ? headerEnd : headerEnd + 1; >- >- auto encodedData = StringView(urlString).substring(encodedDataStart); >- auto header = StringView(urlString).substring(strlen(dataString), headerEnd - strlen(dataString)); >- bool isBase64 = header.endsWithIgnoringASCIICase(StringView(base64String)); >- auto mediaType = (isBase64 ? header.substring(0, header.length() - strlen(base64String)) : header).toString(); >- > return std::make_unique<DecodeTask>( >- urlString, >- WTFMove(encodedData), >- isBase64, >+ url.string(), > scheduleContext, >- WTFMove(completionHandler), >- parseMediaType(mediaType) >+ WTFMove(completionHandler) > ); > } > >@@ -184,10 +185,12 @@ void decode(const URL& url, const ScheduleContext& scheduleContext, DecodeComple > ASSERT(url.protocolIsData()); > > decodeQueue().dispatch([decodeTask = createDecodeTask(url, scheduleContext, WTFMove(completionHandler))]() mutable { >- if (decodeTask->isBase64) >- decodeBase64(*decodeTask); >- else >- decodeEscaped(*decodeTask); >+ if (decodeTask->process()) { >+ if (decodeTask->isBase64) >+ decodeBase64(*decodeTask); >+ else >+ decodeEscaped(*decodeTask); >+ } > > #if HAVE(RUNLOOP_TIMER) > DecodingResultDispatcher::dispatch(WTFMove(decodeTask)); >diff --git a/LayoutTests/imported/w3c/ChangeLog b/LayoutTests/imported/w3c/ChangeLog >index f61b31a52072fc587351db36bd22ba970b998431..28cbc691e92466242c2b15cb733008175272bab8 100644 >--- a/LayoutTests/imported/w3c/ChangeLog >+++ b/LayoutTests/imported/w3c/ChangeLog >@@ -1,3 +1,15 @@ >+2018-12-04 Rob Buis <rbuis@igalia.com> >+ >+ Align with Fetch on data: URLs >+ https://bugs.webkit.org/show_bug.cgi?id=182325 >+ >+ Reviewed by Alex Christensen. >+ >+ Update improved test expectations. >+ >+ * web-platform-tests/fetch/api/basic/scheme-data.any-expected.txt: >+ * web-platform-tests/fetch/api/basic/scheme-data.any.worker-expected.txt: >+ > 2018-11-30 Ryosuke Niwa <rniwa@webkit.org> > > title attribute on style & link elements should be ignored inside a shadow tree >diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-data.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-data.any-expected.txt >index 618c8448e3885160ca9d9a54fceb54b2533f81b7..65b2f320eb760321591a1012ff84a75a164ebec7 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-data.any-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-data.any-expected.txt >@@ -1,3 +1,4 @@ >+CONSOLE MESSAGE: Fetch API cannot load data:notAdataUrl.com. > > PASS Fetching data:,response%27s%20body is OK > PASS Fetching data:,response%27s%20body is OK (same-origin) >@@ -6,5 +7,5 @@ PASS Fetching data:text/plain;base64,cmVzcG9uc2UncyBib[...] is OK > PASS Fetching data:image/png;base64,cmVzcG9uc2UncyBib2[...] is OK > PASS Fetching [POST] data:,response%27s%20body is OK > PASS Fetching [HEAD] data:,response%27s%20body is OK >-FAIL Fetching [GET] data:notAdataUrl.com is KO assert_unreached: Should have rejected: undefined Reached unreachable code >+PASS Fetching [GET] data:notAdataUrl.com is KO > >diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-data.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-data.any.worker-expected.txt >index 618c8448e3885160ca9d9a54fceb54b2533f81b7..c75f064184f5880bdbf54ef85603c3760ade1301 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-data.any.worker-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-data.any.worker-expected.txt >@@ -6,5 +6,5 @@ PASS Fetching data:text/plain;base64,cmVzcG9uc2UncyBib[...] is OK > PASS Fetching data:image/png;base64,cmVzcG9uc2UncyBib2[...] is OK > PASS Fetching [POST] data:,response%27s%20body is OK > PASS Fetching [HEAD] data:,response%27s%20body is OK >-FAIL Fetching [GET] data:notAdataUrl.com is KO assert_unreached: Should have rejected: undefined Reached unreachable code >+PASS Fetching [GET] data:notAdataUrl.com is KO >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 182325
:
356308
|
356310
|
356312
|
356314
|
356319
|
356335
|
356348
|
356359
|
356404
|
356504
|
356588
|
360026
|
360096
|
360101
|
360102
|
360104
|
360106
|
360239
|
360365
|
360367
|
360370
|
360499
|
361798
|
361806
|
361842