Commit 72ea71aa authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Fixed string escaping when writing QML properties.

parent b59442e0
......@@ -97,7 +97,7 @@ QString QmlTextGenerator::toQml(const AbstractProperty &property, int indentDept
return stringValue;
default:
return QString(QLatin1String("\"%1\"")).arg(stringValue);
return QString(QLatin1String("\"%1\"")).arg(escape(stringValue));
}
} else {
Q_ASSERT("Unknown property type");
......@@ -176,3 +176,16 @@ QString QmlTextGenerator::propertyToQml(const AbstractProperty &property, int in
return result;
}
QString QmlTextGenerator::escape(const QString &value)
{
QString result = value;
result.replace(QLatin1String("\\"), QLatin1String("\\\\"));
result.replace(QLatin1String("\""), QLatin1String("\\\""));
result.replace(QLatin1String("\t"), QLatin1String("\\\t"));
result.replace(QLatin1String("\r"), QLatin1String("\\\r"));
result.replace(QLatin1String("\n"), QLatin1String("\\\n"));
return result;
}
......@@ -56,6 +56,8 @@ private:
QString propertiesToQml(const ModelNode &node, int indentDepth) const;
QString propertyToQml(const AbstractProperty &property, int indentDepth) const;
static QString escape(const QString &value);
private:
QStringList m_propertyOrder;
int m_indentDepth;
......
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