diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2010-05-18 04:51:58 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2010-05-18 05:07:44 (GMT) |
commit | 3d1a6596c6a381b71718af22eb8a861830ec7b6b (patch) | |
tree | 9e7be18bdb1358c6c460a12a19653922c0409352 /src/declarative/qml/qdeclarativeparser.cpp | |
parent | 690ad58e03fb064e90e2e66e96419d82d9ee343d (diff) | |
download | Qt-3d1a6596c6a381b71718af22eb8a861830ec7b6b.zip Qt-3d1a6596c6a381b71718af22eb8a861830ec7b6b.tar.gz Qt-3d1a6596c6a381b71718af22eb8a861830ec7b6b.tar.bz2 |
Make sure strings are escaped when returned via asScript.
Makes 273024e58d90bb9b3a5da0161f884f1af22d75df more correct.
Diffstat (limited to 'src/declarative/qml/qdeclarativeparser.cpp')
-rw-r--r-- | src/declarative/qml/qdeclarativeparser.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/declarative/qml/qdeclarativeparser.cpp b/src/declarative/qml/qdeclarativeparser.cpp index b38bd76..8d00ef8 100644 --- a/src/declarative/qml/qdeclarativeparser.cpp +++ b/src/declarative/qml/qdeclarativeparser.cpp @@ -57,6 +57,7 @@ #include <QPointF> #include <QSizeF> #include <QRectF> +#include <QStringBuilder> #include <QtDebug> QT_BEGIN_NAMESPACE @@ -310,6 +311,49 @@ double QDeclarativeParser::Variant::asNumber() const return d; } +//reverse of Lexer::singleEscape() +QString escapedString(const QString &string) +{ + QString tmp = QLatin1String("\""); + for (int i = 0; i < string.length(); ++i) { + const QChar &c = string.at(i); + switch(c.unicode()) { + case 0x08: + tmp += QLatin1String("\\b"); + break; + case 0x09: + tmp += QLatin1String("\\t"); + break; + case 0x0A: + tmp += QLatin1String("\\n"); + break; + case 0x0B: + tmp += QLatin1String("\\v"); + break; + case 0x0C: + tmp += QLatin1String("\\f"); + break; + case 0x0D: + tmp += QLatin1String("\\r"); + break; + case 0x22: + tmp += QLatin1String("\\\""); + break; + case 0x27: + tmp += QLatin1String("\\\'"); + break; + case 0x5C: + tmp += QLatin1String("\\\\"); + break; + default: + tmp += c; + break; + } + } + tmp += QLatin1Char('\"'); + return tmp; +} + QString QDeclarativeParser::Variant::asScript() const { switch(type()) { @@ -324,6 +368,7 @@ QString QDeclarativeParser::Variant::asScript() const else return s; case String: + return escapedString(s); case Script: return s; } |