Squish: Fix object map handling on Windows

Ensure we are using UTF8 all over the place especially when
using external tools and their stdin or stdout streams.
This fixes bad encoding issues on Windows when having unicode
characters inside the objects map file.

Change-Id: Ic8e66a876abe0903308002cd25315b1eaa3788b1
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2022-11-11 12:50:59 +01:00
parent 3922ee3c72
commit b55c10f189
4 changed files with 16 additions and 13 deletions

View File

@@ -12,7 +12,7 @@
#include <utils/fileutils.h>
#include <utils/qtcprocess.h>
#include <QDir>
#include <QtCore5Compat/QTextCodec>
namespace Squish {
namespace Internal {
@@ -187,13 +187,13 @@ Core::IDocument::OpenResult ObjectsMapDocument::openImpl(QString *error,
if (fileName.isEmpty())
return OpenResult::CannotHandle;
QString text;
QByteArray text;
if (realFileName.fileName() == "objects.map") {
Utils::FileReader reader;
if (!reader.fetch(realFileName, QIODevice::Text, error))
return OpenResult::ReadError;
text = QString::fromLocal8Bit(reader.data());
text = reader.data();
} else {
const Utils::FilePath base = SquishPlugin::squishSettings()->squishPath.filePath();
if (base.isEmpty()) {
@@ -212,11 +212,12 @@ Core::IDocument::OpenResult ObjectsMapDocument::openImpl(QString *error,
Utils::QtcProcess objectMapReader;
objectMapReader.setCommand({exe, {"--scriptMap", "--mode", "read",
"--scriptedObjectMapPath", realFileName.toUserOutput()}});
objectMapReader.setCodec(QTextCodec::codecForName("UTF-8"));
objectMapReader.start();
objectMapReader.waitForFinished();
text = objectMapReader.cleanedStdOut();
text = objectMapReader.cleanedStdOut().toUtf8();
}
if (!setContents(text.toUtf8())) {
if (!setContents(text)) {
if (error)
error->append(Tr::tr("Failure while parsing objects.map content."));
return OpenResult::ReadError;

View File

@@ -346,7 +346,7 @@ void ObjectsMapEditorWidget::onPropertiesContentModified(const QString &text)
const QModelIndex &idx = m_objMapFilterModel->mapToSource(selected.first());
if (auto item = static_cast<ObjectsMapTreeItem *>(m_document->model()->itemForIndex(idx)))
item->setPropertiesContent(text.toLocal8Bit().trimmed());
item->setPropertiesContent(text.toUtf8().trimmed());
}
void ObjectsMapEditorWidget::onJumpToSymbolicNameClicked()

View File

@@ -130,19 +130,20 @@ bool ObjectsMapTreeItem::parseProperties(const QByteArray &properties)
if (properties.isEmpty() || properties.at(0) != '{')
return false;
QString p = QString::fromUtf8(properties);
ParseState state = None;
QByteArray name;
QByteArray value;
QByteArray oper;
QString name;
QString value;
QString oper;
bool masquerading = false;
for (char c : properties) {
for (QChar c : p) {
if (masquerading) {
value.append('\\').append(c);
masquerading = false;
continue;
}
switch (c) {
switch (c.unicode()) {
case '=':
if (state == Value) {
value.append(c);
@@ -172,7 +173,7 @@ bool ObjectsMapTreeItem::parseProperties(const QByteArray &properties)
} else if (state == Value) {
state = None;
Property prop;
if (!prop.set(QLatin1String(name), QLatin1String(oper), QLatin1String(value))) {
if (!prop.set(name, oper, value)) {
propertyRoot->removeChildren();
return false;
}
@@ -214,7 +215,7 @@ bool ObjectsMapTreeItem::parseProperties(const QByteArray &properties)
}
break;
default:
if (QChar::isSpace(c)) {
if (c.isSpace()) {
if (state == Value) {
value.append(c);
} else if (state == Name) {

View File

@@ -10,6 +10,7 @@ QtcPlugin {
Depends { name: "Utils" }
Depends { name: "Qt.widgets" }
Depends { name: "Qt.core5compat" }
files: [
"deletesymbolicnamedialog.cpp",