From 4fb458c9e739283c5d77bff67d08dcba935d6984 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Fri, 10 Apr 2015 09:35:41 +0200 Subject: Fix parsing of encoded xml attributes If an xml attribute contains an entity parsing it failed due to missing decoding. This patch decodes entities holding (hexa-)decimal entities. This is especially necessary for files (or paths) containing some special characters that might end up encoded inside the output that would be generated by running the tests. Change-Id: I4f3b9f9edc59ff1433b92ed4ce1933eaf29ffe74 Reviewed-by: David Schulz --- plugins/autotest/testxmloutputreader.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/plugins/autotest/testxmloutputreader.cpp b/plugins/autotest/testxmloutputreader.cpp index d8b3400d6b..8d0fa72235 100644 --- a/plugins/autotest/testxmloutputreader.cpp +++ b/plugins/autotest/testxmloutputreader.cpp @@ -20,7 +20,7 @@ #include "testxmloutputreader.h" #include "testresult.h" -#include +#include #include #include #include @@ -28,6 +28,25 @@ namespace Autotest { namespace Internal { +static QString decode(const QString& original) +{ + QString result(original); + static QRegExp regex(QLatin1String("&#((x[0-9A-F]+)|([0-9]+));"), Qt::CaseInsensitive); + regex.setMinimal(true); + + int pos = 0; + while ((pos = regex.indexIn(original, pos)) != -1) { + const QString value = regex.cap(1); + if (value.startsWith(QLatin1Char('x'))) + result.replace(regex.cap(0), QChar(value.mid(1).toInt(0, 16))); + else + result.replace(regex.cap(0), QChar(value.toInt(0, 10))); + pos += regex.matchedLength(); + } + + return result; +} + static bool xmlStartsWith(const QString &code, const QString &start, QString &result) { if (code.startsWith(start)) { @@ -57,7 +76,7 @@ static bool xmlExtractTypeFileLine(const QString &code, const QString &tagStart, result = TestResult::resultFromString( code.mid(start, code.indexOf(QLatin1Char('"'), start) - start)); start = code.indexOf(QLatin1String(" file=\"")) + 7; - file = code.mid(start, code.indexOf(QLatin1Char('"'), start) - start); + file = decode(code.mid(start, code.indexOf(QLatin1Char('"'), start) - start)); start = code.indexOf(QLatin1String(" line=\"")) + 7; line = code.mid(start, code.indexOf(QLatin1Char('"'), start) - start).toInt(); return true; -- cgit v1.2.1