The message text needs to be escaped before beign evaluated.
Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all
Unified · Split
| @@ -49,7 +49,11 @@ static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* eng · 48 unmodified lines | ||
| 49 | 49 | |
| 50 | 50 | static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ |
| 51 | 51 | qDebug() << "script:print()<<" << context->argument(0).toString(); |
| 52 | − engine->evaluate("Script.print('" + context->argument(0).toString() + "')"); | |
| 52 | + QString message = context->argument(0).toString() | |
| 53 | + .replace("\\", "\\\\") | |
| 54 | + .replace("\n", "\\n") | |
| 55 | + .replace("'", "\\'"); | |
| 56 | + engine->evaluate("Script.print('" + message + "')"); | |
| 53 | 57 | return QScriptValue(); |
| 54 | 58 | } |
| 55 | 59 | |