summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qdataurl.cpp
Commit message (Collapse)AuthorAgeFilesLines
* qdataurl: fix parsing parameter values with percent-encoded commaAhmad Samir2025-06-011-3/+6
| | | | | Change-Id: I2faa8ce7c9932eb82a853421290c39a37ad91bcf Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qdataurl: modify the percent-decoded byte array directlyAhmad Samir2025-06-011-23/+22
| | | | | | | | | | | | | | Parse the content-type first, then slice the byte array. This is useful especially for large base64 payloads. Drive-by, use QUrl::toEncoded(), it's the same result but more succinct syntax; pointed out in code review. Also remove an old comment, it's not relevant anymore since QUrl::encodedPath() isn't available any more in Qt 6.0: https://code.qt.io/cgit/qt/qt.git/commit/?id=c0d237b7aa6e0257e3c3eee7336deaed1cf68252 Change-Id: Id69345f315dab934d0f2867008bf4fe29d63cac9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Mark QUrl* classes as security-criticalMarc Mutz2025-05-301-0/+1
| | | | | | | | | | | | | These classes, too, are usually in the first line of defense, handling tainted data before anything else had the chance to verify it. Amends 8df072fc8006510c9b743e8ffedaaf51a876883a. QUIP: 23 Task-number: QTBUG-135187 Pick-to: 6.9 6.8 Change-Id: I21dbea39078a583f0bbf7737bd7151893fb98d17 Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
* qdataurl: make parsing the content-type more robustAhmad Samir2025-05-241-10/+35
| | | | | | | | | | | | | Don't assume `charset` is the first parameter. The parameters (attribute=value pairs) are delemited by a `;`. The order of the parameters isn't specified, (except for `;base64` which is the last one). Add more tests. Add a test for image/png (.png file copied from src/widgets/styles/images/arrow-down-16.png). Change-Id: Ie3e45c607c093695d0c180e9a9783b2b02d7ef70 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qdataurl: use QLatin1StringView instead of QByteArrayViewAhmad Samir2025-05-241-9/+9
| | | | | | | | | | | | | This is URL data and we use toLatin1() to convert from QString to QByteArray. QL1SV is more suitable here because we need to do case-insensitive look ups into the <mediatype> (see https://www.rfc-editor.org/rfc/rfc2397.html) part of the URL. Drive by, use QL1SV::sliced() instead of mid(), the precondition has already been checked. Change-Id: I670c41fdb6728f6420b1a4e2046357013ea210e0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qdataurl: optimize by using QByteArray::fromBase64Encoding()Ahmad Samir2025-05-241-2/+8
| | | | | | | It takes by rvalue and does the decoding in-place. Change-Id: Ie49c46128b52d302ea69786471756039936ec7e1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qdataurl: treat comma as mandatory in the data URL syntaxAhmad Samir2025-05-241-1/+2
| | | | | | | | | | | | | | | | | | | | In the syntax specified in https://www.rfc-editor.org/rfc/rfc2397.html: data:[<mediatype>][;base64],<data> The comma isn't inside square brackets, so not optional. Change the unittests accordingly, "data:text/plain" isn't empty data, it's rather malformed. [ChangeLog][QtCore] Changed parsing 'data:' URLs to report failure if the comma is missing, this makes it more compliant with RFC 2397. [ChangeLog][QtNetwork][QNetworkManager] Changed parsing 'data:' URLs to report failure if the comma is missing, this makes it more compliant RFC 2397. Change-Id: I91c45f42257de7840ab45c0f8eb31b8df3d483bc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qdataurl: don't set the mime type too earlyAhmad Samir2025-05-241-2/+2
| | | | | | | | | 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>
* qDecodeDataUrl(): fix precondition violation in call to QByteArrayView::at()Marc Mutz2025-04-281-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | It is a precondition violation to call QByteArrayView::at() with size() as argument. The code used that, though, as an implicit end-of-string check, assuming == ' ' and == '=' would both fail for null bytes. Besides, QByteArrays (but most certainly QByteArrayViews) need not be null-terminated, so this could read even past size(). To fix, use higher-level API (startsWith()), consuming parsed tokens along the way. Add a test that would crash in debug mode before the fix. Amends the start of the public history. [ChangeLog][QtCore] Fixed a bug in the handling of data: URLs that could lead to a crash if Qt was built with assertions enabled. This affects QNetworkManager and links in QTextDocument. Pick-to: 6.9 6.8 6.5 6.5.9 6.2 5.15 Change-Id: I4331c88051dfbb0a18fe7da4f50858c707785d09 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* qdataurl: extract string literalsAnton Kudryavtsev2023-09-101-4/+6
| | | | | | | to reuse size() to avoid magic numbers Change-Id: Id1dc69a024ce5597c2d1468e7cb1470df728d84c Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* qDecodeDataUrl: use QL1S moreAnton Kudryavtsev2023-09-051-3/+3
| | | | | | | | Avoid tmp QBA creation, just wrap QBAV to QL1S for QSB expression Change-Id: I8395bd2db2aab29a6b4965071b022c0487bddcb6 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* qDecodeDataUrl: use QBAV moreAnton Kudryavtsev2023-09-021-5/+7
| | | | | | | to reduce allocations Change-Id: Ia2d68186ee56556152254c6579a52131b246b07f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Fix int/qsizetype mismatches in data url supportMarc Mutz2022-08-211-2/+2
| | | | | | | | | | More int/qsizetype mismatches. Task-number: QTBUG-103525 Pick-to: 6.4 6.3 6.2 Change-Id: I30723b6f59fa62dd7096110458305da7573ad345 Reviewed-by: Mate Barany <mate.barany@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QtCore: Replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-03-261-2/+2
| | | | | | | Task-number: QTBUG-98434 Change-Id: Ib7c5fc0aaca6ef33b93c7486e99502c555bf20bc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QtCore: replace QLatin1String/QLatin1Char with _L1/u'' where applicableSona Kurazyan2022-03-251-1/+1
| | | | | | | | | | | As a drive-by, did also minor refactorings/improvements. Task-number: QTBUG-98434 Change-Id: I81964176ae2f07ea63674c96f47f9c6aa046854f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
* qDecodeDataUrl(): treat ";base64" marker as case-insensitiveMarc Mutz2022-03-111-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | RFC2397 doesn't explicitly mention it, but references RFC2045, which, in Section 2, states: > All media type values, subtype values, and parameter names as > defined are case-insensitive. and goes on, in 6.1: > mechanism := "7bit" / "8bit" / "binary" / > "quoted-printable" / "base64" / > ietf-token / x-token > > These values are not case sensitive So regardless of whether "base64" is a parameter name, or a mechanism, we need to treat it case-insensitively. Use QLatin1String::endsWith() instead of QByteArray::endsWith(), because the former takes Qt::CaseInsensitive while the latter would need a toLower(). Add a test. As a drive-by, use the same trick for the existing case-insensitive comparison with "charset". As a further drive-by, fix inappropriate uses of QLatin1String (= where they don't prevent allocations). [ChangeLog][QtCore][QUrl] Now recognizes the ";base64" marker in "data:" URLs case-insensitively. Pick-to: 6.3 6.2 Change-Id: Ife6ba771553aaad3b7c119c1fa631f41ffa8f590 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Updated license headersJani Heikkinen2016-01-151-14/+20
| | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Update copyright headersJani Heikkinen2015-02-111-7/+7
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* Update license headers and add new license filesMatti Paaso2014-09-241-19/+11
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* Update copyright year in Digia's license headersSergio Ahumada2013-01-181-1/+1
| | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-221-24/+24
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* Fix qDecodeDataUrl for already percentage encoded content.Alexis Menard2012-05-091-2/+2
| | | | | | | | | | | If the url we pass as parameter already have percentage encoded data, we don't want to decode it and call fromPercentEncoding. The test coverage is not complete for qdataurl.cpp file but it is better than previously and it will also protect us from future regressions. Change-Id: I79f709f44bed1b7f274a3de639c7e291fa91a193 Reviewed-by: Thiago Macieira Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Long live the new QUrl implementation.Thiago Macieira2012-03-301-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also say hello to QUrl's constructor and QUrl::toString being allowed again. QUrl operates now on UTF-16 encoded data, where a Unicode character matches its UTF-8 percent-encoded form (as per RFC 3987). The data may exist in different levels of encoding, but it is always in encoded form (a percent is always "%25"). For that reason, the previously dangerous methods are no longer dangerous. The QUrl parser is much more lenient now. Instead of blindly following the grammar from RFC 3986, we try to use common-sense. Hopefully, this will also mean the code is faster. It also operates on QStrings and, for the common case, will not perform any memory allocations it doesn't keep (i.e., it allocates only for the data that is stored in QUrlPrivate). The Null/Empty behaviour that fragments and queries had in Qt4 are now extended to the scheme, username, password and host parts. This means QUrl can remember the difference between "http://@example.com" and "http://example.com". Missing from this commit: - more unit tests, for the new functionality - the implementation of the StrictMode parser - errorString() support - normalisation Change-Id: I6d340b19c1a11b98a48145152513ffec58fb3fe3 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Remove "All rights reserved" line from license headers.Jason McDonald2012-01-301-1/+1
| | | | | | | | | | As in the past, to avoid rewriting various autotests that contain line-number information, an extra blank line has been inserted at the end of the license text to ensure that this commit does not change the total number of lines in the license header. Change-Id: I311e001373776812699d6efc045b5f742890c689 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update contact information in license headers.Jason McDonald2012-01-231-1/+1
| | | | | | | Replace Nokia contact email address with Qt Project website. Change-Id: I431bbbf76d7c27d8b502f87947675c116994c415 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update copyright year in license headers.Jason McDonald2012-01-051-1/+1
| | | | | Change-Id: I02f2c620296fcd91d4967d58767ea33fc4e1e7dc Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Make qDecodeDataUrl return bool.Jonas M. Gastal2011-12-291-34/+32
| | | | | Change-Id: I23b9fed39af7bea6c171b35e10bd72c424bd903e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update licenseheader text in source files for qtbase Qt moduleJyri Tahtela2011-05-241-17/+17
| | | | | | | Updated version of LGPL and FDL licenseheaders. Apply release phase licenseheaders for all source files. Reviewed-by: Trust Me
* Initial import from the monolithic Qt.Qt by Nokia2011-04-271-0/+101
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12