From df6ba4bc1671c26e17dd09b93ff770d55f1bf60e Mon Sep 17 00:00:00 2001 From: Ievgenii Meshcheriakov Date: Tue, 4 Oct 2022 15:21:02 +0200 Subject: [PATCH] tst_qurluts46: Support \u escapes in the test data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Thiago Macieira --- .../corelib/io/qurluts46/tst_qurluts46.cpp | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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 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("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];