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 <david.schulz@theqtcompany.com>
This commit is contained in:
Christian Stenger
2015-04-10 09:35:41 +02:00
parent 97a8806417
commit 4fb458c9e7

View File

@@ -20,7 +20,7 @@
#include "testxmloutputreader.h"
#include "testresult.h"
#include <QXmlStreamReader>
#include <QRegExp>
#include <QProcess>
#include <QFileInfo>
#include <QDir>
@@ -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;