Commit 7d25b909 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

TypeDescriptionReader: Check for files that are not UTF8 encoded



We had a qmltypes file that was encoded in UTF16 and did not work.
We should at least warn about it.

Change-Id: I42555782ee16ddd25552f919845aa85ff1f3f636
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent 3604bdba
......@@ -39,6 +39,7 @@
#include <utils/qtcassert.h>
#include <QApplication>
#include <QFile>
#include <QDir>
#include <QString>
......@@ -1253,7 +1254,8 @@ CppQmlTypesLoader::BuiltinObjects CppQmlTypesLoader::loadQmlTypes(const QFileInf
QByteArray contents = file.readAll();
file.close();
parseQmlTypeDescriptions(contents, &newObjects, 0, &error, &warning);
parseQmlTypeDescriptions(contents, &newObjects, 0, &error, &warning, qmlTypeFile.absoluteFilePath());
} else {
error = file.errorString();
}
......@@ -1272,15 +1274,28 @@ CppQmlTypesLoader::BuiltinObjects CppQmlTypesLoader::loadQmlTypes(const QFileInf
return newObjects;
}
void CppQmlTypesLoader::parseQmlTypeDescriptions(const QByteArray &xml,
void CppQmlTypesLoader::parseQmlTypeDescriptions(const QByteArray &contents,
BuiltinObjects *newObjects,
QList<ModuleApiInfo> *newModuleApis,
QString *errorMessage,
QString *warningMessage)
{
QString *warningMessage, const QString &fileName)
{
if (!contents.isEmpty()) {
unsigned char c = contents.at(0);
switch (c) {
case 0xfe:
case 0xef:
case 0xff:
case 0xee:
case 0x00:
qWarning() << QApplication::translate("CppQmlTypesLoader", "%1 seems not to be encoded in UTF8 or has a BOM.").arg(fileName);
default: break;
}
}
errorMessage->clear();
warningMessage->clear();
TypeDescriptionReader reader(QString::fromUtf8(xml));
TypeDescriptionReader reader(QString::fromUtf8(contents));
if (!reader(newObjects, newModuleApis)) {
if (reader.errorMessage().isEmpty())
*errorMessage = QLatin1String("unknown error");
......
......@@ -608,10 +608,9 @@ public:
static BuiltinObjects defaultLibraryObjects;
// parses the contents of a qmltypes file and fills the newObjects map
static void parseQmlTypeDescriptions(
const QByteArray &qmlTypes,
static void parseQmlTypeDescriptions(const QByteArray &contents,
BuiltinObjects *newObjects,
QList<ModuleApiInfo> *newModuleApis, QString *errorMessage, QString *warningMessage);
QList<ModuleApiInfo> *newModuleApis, QString *errorMessage, QString *warningMessage, const QString &fileName);
};
class QMLJS_EXPORT CppQmlTypes
......
......@@ -326,7 +326,8 @@ void PluginDumper::qmlPluginTypeDumpDone(int exitCode)
QString warning;
CppQmlTypesLoader::BuiltinObjects objectsList;
QList<ModuleApiInfo> moduleApis;
CppQmlTypesLoader::parseQmlTypeDescriptions(output, &objectsList, &moduleApis, &error, &warning);
CppQmlTypesLoader::parseQmlTypeDescriptions(output, &objectsList, &moduleApis, &error, &warning,
QLatin1String("<dump of ") + libraryPath + QLatin1String(">"));
if (exitCode == 0) {
if (!error.isEmpty()) {
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError,
......@@ -397,7 +398,7 @@ void PluginDumper::loadQmltypesFile(const QStringList &qmltypesFilePaths,
QString warning;
CppQmlTypesLoader::BuiltinObjects newObjects;
QList<ModuleApiInfo> newModuleApis;
CppQmlTypesLoader::parseQmlTypeDescriptions(reader.data(), &newObjects, &newModuleApis, &error, &warning);
CppQmlTypesLoader::parseQmlTypeDescriptions(reader.data(), &newObjects, &newModuleApis, &error, &warning, qmltypesFilePath);
if (!error.isEmpty()) {
errors += tr("Failed to parse '%1'.\nError: %2").arg(qmltypesFilePath, error);
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment