summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-06-07 18:56:58 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-06-21 02:31:38 +0200
commit6827a3aa2bc852152cd3353be9558c683fb3085c (patch)
tree8b56250ed0ab85005463b23385698e935f762c96 /src/corelib/io
parent154823904672bd89255dd647a2fe609f8fbd74b0 (diff)
QUrl stringprep: fix handling of prohibited characters
RFC 3454 says about prohibited characters (section 2, "Preparation Overview"): 3) Prohibit -- Check for any characters that are not allowed in the output. If any are found, return an error. This is described in section 5. In other words, we mustn't simply strip the output of prohibited characters. We must generate an error if they are present. We do that by clearing the data. We already had tests for prohibited output, but they were indistinguishable from being stripped. So instead add some extra characters so that we can tell whether the label was cleared. (cherry-picked from qtbase commit 736a052d93d9c75e51e8f3da733bc8e4a50c39ce) Change-Id: I2d95217c27be5e2d54deed0036cb009e3b7f4886 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qurl.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 14b9037328..3dc956888c 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -2438,18 +2438,20 @@ static bool isMappedToNothing(uint uc)
}
-static void stripProhibitedOutput(QString *str, int from)
+static bool containsProhibitedOuptut(const QString *str, int from)
{
- ushort *out = (ushort *)str->data() + from;
- const ushort *in = out;
+ const ushort *in = reinterpret_cast<const ushort *>(str->begin() + from);
const ushort *end = (ushort *)str->data() + str->size();
- while (in < end) {
+ for ( ; in < end; ++in) {
uint uc = *in;
if (QChar(uc).isHighSurrogate() && in < end - 1) {
ushort low = *(in + 1);
if (QChar(low).isLowSurrogate()) {
++in;
uc = QChar::surrogateToUcs4(uc, low);
+ } else {
+ // unpaired surrogates are prohibited
+ return true;
}
}
if (uc <= 0xFFFF) {
@@ -2474,7 +2476,7 @@ static void stripProhibitedOutput(QString *str, int from)
|| (uc >= 0xFDD0 && uc <= 0xFDEF)
|| uc == 0xFEFF
|| (uc >= 0xFFF9 && uc <= 0xFFFF))) {
- *out++ = *in;
+ continue;
}
} else {
if (!((uc >= 0x1D173 && uc <= 0x1D17A)
@@ -2498,14 +2500,12 @@ static void stripProhibitedOutput(QString *str, int from)
|| (uc >= 0xFFFFE && uc <= 0xFFFFF)
|| (uc >= 0x100000 && uc <= 0x10FFFD)
|| (uc >= 0x10FFFE && uc <= 0x10FFFF))) {
- *out++ = QChar::highSurrogate(uc);
- *out++ = QChar::lowSurrogate(uc);
+ continue;
}
}
- ++in;
+ return true;
}
- if (in != out)
- str->truncate(out - str->utf16());
+ return false;
}
static bool isBidirectionalRorAL(uint uc)
@@ -3030,7 +3030,10 @@ void qt_nameprep(QString *source, int from)
firstNonAscii > from ? firstNonAscii - 1 : from);
// Strip prohibited output
- stripProhibitedOutput(source, firstNonAscii);
+ if (containsProhibitedOuptut(source, firstNonAscii)) {
+ source->resize(from);
+ return;
+ }
// Check for valid bidirectional characters
bool containsLCat = false;