Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
2008-10-04 Alp Toker <alp@nuanti.com>
        Reviewed by David Hyatt. Landed by Jan Alonzo.

        https://bugs.webkit.org/show_bug.cgi?id=20924
        [Gtk] Linux/Gtk: Recent tree revisions fail Acid2 and Acid3

        https://bugs.webkit.org/show_bug.cgi?id=19578
        [CURL] problem in parseDataUrl

        De-obfuscate parseDataUrl() and fix regressions introduced in r35954.
        This patch also fixes encoding support in escaped (non-Base64) data
        URLs. All manual data URL tests now pass in both GLib and non-GLib
        code paths.

        * platform/network/curl/ResourceHandleManager.cpp:
        (WebCore::parseDataUrl):

Canonical link: https://commits.webkit.org/29570@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@37314 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Jan Alonzo committed Oct 5, 2008
1 parent c281385 commit 0823ce5
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 50 deletions.
18 changes: 18 additions & 0 deletions WebCore/ChangeLog
@@ -1,3 +1,21 @@
2008-10-04 Alp Toker <alp@nuanti.com>

Reviewed by David Hyatt. Landed by Jan Alonzo.

https://bugs.webkit.org/show_bug.cgi?id=20924
[Gtk] Linux/Gtk: Recent tree revisions fail Acid2 and Acid3

https://bugs.webkit.org/show_bug.cgi?id=19578
[CURL] problem in parseDataUrl

De-obfuscate parseDataUrl() and fix regressions introduced in r35954.
This patch also fixes encoding support in escaped (non-Base64) data
URLs. All manual data URL tests now pass in both GLib and non-GLib
code paths.

* platform/network/curl/ResourceHandleManager.cpp:
(WebCore::parseDataUrl):

2008-10-04 Timothy Hatcher <timothy@apple.com>

Makes breakpoints and debugging code during page load work in the
Expand Down
99 changes: 49 additions & 50 deletions WebCore/platform/network/curl/ResourceHandleManager.cpp
@@ -1,9 +1,10 @@
/*
* Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
* Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
* Copyright (C) 2007 Alp Toker <alp@atoker.com>
* Copyright (C) 2007 Holger Hans Peter Freyther
* Copyright (C) 2008 Collabora Ltd.
* Copyright (C) 2008 Nuanti Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -31,14 +32,15 @@
#include "config.h"
#include "ResourceHandleManager.h"

#include "Base64.h"
#include "CString.h"
#include "HTTPParsers.h"
#include "MIMETypeRegistry.h"
#include "NotImplemented.h"
#include "ResourceError.h"
#include "ResourceHandle.h"
#include "ResourceHandleInternal.h"
#include "HTTPParsers.h"
#include "Base64.h"
#include "TextEncoding.h"

#include <errno.h>
#include <wtf/Vector.h>
Expand Down Expand Up @@ -468,68 +470,65 @@ bool ResourceHandleManager::startScheduledJobs()
return started;
}

// FIXME: This function does not deal properly with text encodings.
static void parseDataUrl(ResourceHandle* handle)
{
String data = handle->request().url().string();

ASSERT(data.startsWith("data:", false));

String header;
bool base64 = false;
ResourceHandleClient* client = handle->client();

int index = data.find(',');
if (index != -1) {
header = data.substring(5, index - 5).lower();
data = data.substring(index + 1);

if (header.endsWith(";base64")) {
base64 = true;
header = header.left(header.length() - 7);
}
} else
data = String();
ASSERT(client);
if (!client)
return;

data = decodeURLEscapeSequences(data);
String url = handle->request().url().string();
ASSERT(url.startsWith("data:", false));

size_t outLength = 0;
char* outData = 0;
Vector<char> out;
if (base64 && !data.isEmpty()) {
// Use the GLib Base64 if available, since WebCore's decoder isn't
// general-purpose and fails on Acid3 test 97 (whitespace).
#ifdef USE_GLIB_BASE64
outData = reinterpret_cast<char*>(g_base64_decode(data.utf8().data(), &outLength));
#else
base64Decode(data.latin1().data(), data.length(), out);
#endif
int index = url.find(',');
if (index == -1) {
client->cannotShowURL(handle);
return;
}

if (header.isEmpty())
header = "text/plain;charset=US-ASCII";
String mediaType = url.substring(5, index - 5);
String data = url.substring(index + 1);

ResourceHandleClient* client = handle->getInternal()->client();
bool base64 = mediaType.endsWith(";base64", false);
if (base64)
mediaType = mediaType.left(mediaType.length() - 7);

ResourceResponse response;
if (mediaType.isEmpty())
mediaType = "text/plain;charset=US-ASCII";

response.setMimeType(extractMIMETypeFromMediaType(header));
response.setTextEncodingName(extractCharsetFromMediaType(header));
if (outData)
response.setExpectedContentLength(outLength);
else
response.setExpectedContentLength(data.length());
response.setHTTPStatusCode(200);
String mimeType = extractMIMETypeFromMediaType(mediaType);
String charset = extractCharsetFromMediaType(mediaType);

client->didReceiveResponse(handle, response);
ResourceResponse response;
response.setMimeType(mimeType);

if (outData)
client->didReceiveData(handle, outData, outLength, 0);
else
client->didReceiveData(handle, out.data(), out.size(), 0);
if (base64) {
data = decodeURLEscapeSequences(data);
response.setTextEncodingName(charset);
client->didReceiveResponse(handle, response);

// Use the GLib Base64 if available, since WebCore's decoder isn't
// general-purpose and fails on Acid3 test 97 (whitespace).
#ifdef USE_GLIB_BASE64
g_free(outData);
size_t outLength = 0;
char* outData = 0;
outData = reinterpret_cast<char*>(g_base64_decode(data.utf8().data(), &outLength));
if (outData)
client->didReceiveData(handle, outData, outLength, 0);
g_free(outData);
#else
Vector<char> out;
if (base64Decode(data.latin1().data(), data.latin1().length(), out))
client->didReceiveData(handle, out.data(), out.size(), 0);
#endif
} else {
// We have to convert to UTF-16 early due to limitations in KURL
data = decodeURLEscapeSequences(data, TextEncoding(charset));
response.setTextEncodingName("UTF-16");
client->didReceiveResponse(handle, response);
client->didReceiveData(handle, reinterpret_cast<const char*>(data.characters()), data.length() * sizeof(UChar), 0);
}

client->didFinishLoading(handle);
}
Expand Down

0 comments on commit 0823ce5

Please sign in to comment.