diff options
author | Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> | 2022-10-04 15:21:02 +0200 |
---|---|---|
committer | Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> | 2022-10-06 14:26:25 +0200 |
commit | df6ba4bc1671c26e17dd09b93ff770d55f1bf60e (patch) | |
tree | 213589c8a40e75f20b3f6cc2935efd59cf23b97f /tests/auto/corelib/io | |
parent | 9d1e9285129b4c65c978c806bb839798ace61a60 (diff) |
tst_qurluts46: Support \u escapes in the test data
These escapes were documented but not used until the version 15.0.0
of Unicode.
Task-number: QTBUG-106810
Change-Id: If48dcd80acf32989e3f47676ca3d41848a325c0e
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r-- | tests/auto/corelib/io/qurluts46/tst_qurluts46.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/tests/auto/corelib/io/qurluts46/tst_qurluts46.cpp b/tests/auto/corelib/io/qurluts46/tst_qurluts46.cpp index 9d738941ef..7d2d1a741e 100644 --- a/tests/auto/corelib/io/qurluts46/tst_qurluts46.cpp +++ b/tests/auto/corelib/io/qurluts46/tst_qurluts46.cpp @@ -30,6 +30,35 @@ private: const QSet<QByteArray> tst_QUrlUts46::fatalErrors = { "A3", "A4_2", "P1", "X4_2" }; +/** + * Replace \uXXXX escapes in test case fields. + */ +static QString unescapeField(const QString &field) +{ + static const QRegularExpression re(R"(\\u([[:xdigit:]]{4}))"); + + QString result; + qsizetype lastIdx = 0; + + for (const auto &match : re.globalMatch(field)) { + // Add stuff before the match + result.append(field.mid(lastIdx, match.capturedStart() - lastIdx)); + bool ok = false; + auto c = match.captured(1).toUInt(&ok, 16); + if (!ok) { + qFatal("Failed to parse a Unicode escape: %s", qPrintable(match.captured(1))); + } + + result.append(QChar(c)); + lastIdx = match.capturedEnd(); + } + + // Append the unescaped end + result.append(field.mid(lastIdx)); + + return result; +} + void tst_QUrlUts46::idnaTestV2_data() { QTest::addColumn<QString>("source"); @@ -69,7 +98,7 @@ void tst_QUrlUts46::idnaTestV2_data() Q_ASSERT(fields.size() == 7); for (auto &field : fields) - field = field.trimmed(); + field = unescapeField(field.trimmed()).toUtf8(); const QString &source = fields[0]; QString toUnicode = fields[1].isEmpty() ? source : fields[1]; |