qdataurl: don't set the mime type too early
If there is no actual data to decode, setting the mime type is redundant. Also only set the mime type to the default if none is specified in the URL. Change-Id: I19f7ae98c7f1f4483069f580bea028a84a719656 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
8df6859f08
commit
71bcd74542
@ -20,8 +20,6 @@ Q_CORE_EXPORT bool qDecodeDataUrl(const QUrl &uri, QString &mimeType, QByteArray
|
||||
if (uri.scheme() != "data"_L1 || !uri.host().isEmpty())
|
||||
return false;
|
||||
|
||||
mimeType = QStringLiteral("text/plain;charset=US-ASCII");
|
||||
|
||||
// the following would have been the correct thing, but
|
||||
// reality often differs from the specification. People have
|
||||
// data: URIs with ? and #
|
||||
@ -56,6 +54,8 @@ Q_CORE_EXPORT bool qDecodeDataUrl(const QUrl &uri, QString &mimeType, QByteArray
|
||||
|
||||
if (!data.isEmpty())
|
||||
mimeType = textPlain + QLatin1StringView(data.trimmed());
|
||||
else
|
||||
mimeType = QStringLiteral("text/plain;charset=US-ASCII");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -31,8 +31,7 @@ void tst_QDataUrl::decode_data()
|
||||
row("malformed-host", "data://test.com", false);
|
||||
row("malformed-host2", "data://text/plain;charset=ISO-8859-1", false);
|
||||
row("malformed-host3", "data://test.com/,", false);
|
||||
row("emptyData", "data:text/plain", true,
|
||||
"text/plain;charset=US-ASCII"_L1);
|
||||
row("emptyData", "data:text/plain", true);
|
||||
row("emptyData-default-mimetype", "data:,", true,
|
||||
"text/plain;charset=US-ASCII"_L1, "");
|
||||
row("emptyData-only-charset", "data:charset=ISO-8859-1,", true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user