diff options
| author | Ahmad Samir <a.samirh78@gmail.com> | 2025-04-26 14:36:22 +0300 |
|---|---|---|
| committer | Ahmad Samir <a.samirh78@gmail.com> | 2025-05-24 01:12:55 +0300 |
| commit | 0b8f0123e01d995e77a1d9c000b488d75041e7bc (patch) | |
| tree | ef9b0d6681622ba5b34c7f47d67735a59345742b /src/corelib/io/qdataurl.cpp | |
| parent | cec5066f322609c39040d53e314021600e50027b (diff) | |
qdataurl: optimize by using QByteArray::fromBase64Encoding()
It takes by rvalue and does the decoding in-place.
Change-Id: Ie49c46128b52d302ea69786471756039936ec7e1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qdataurl.cpp')
| -rw-r--r-- | src/corelib/io/qdataurl.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/corelib/io/qdataurl.cpp b/src/corelib/io/qdataurl.cpp index 208a432e7a6..b946f2bae44 100644 --- a/src/corelib/io/qdataurl.cpp +++ b/src/corelib/io/qdataurl.cpp @@ -36,9 +36,15 @@ Q_CORE_EXPORT bool qDecodeDataUrl(const QUrl &uri, QString &mimeType, QByteArray data = data.trimmed(); // find out if the payload is encoded in Base64 - constexpr auto base64 = ";base64"_L1; + constexpr auto base64 = ";base64"_L1; // per the RFC, at the end of `data` if (QLatin1StringView{data}.endsWith(base64, Qt::CaseInsensitive)) { - payload = QByteArray::fromBase64(payload); + auto r = QByteArray::fromBase64Encoding(std::move(payload)); + if (!r) { + // just in case someone uses `payload` without checking the returned bool + payload = {}; + return false; // decoding failed + } + payload = std::move(r.decoded); data.chop(base64.size()); } |
