diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-06-01 19:05:31 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-03 09:44:10 (GMT) |
commit | c7d269eab57982517d6fcebea051ad3d8ec955a3 (patch) | |
tree | a7d2cd3e5c2dcb504a3f7d6deef36c7f994addc3 | |
parent | c642dfce4066b6af80e344a60917598ad053a411 (diff) | |
download | Qt-c7d269eab57982517d6fcebea051ad3d8ec955a3.zip Qt-c7d269eab57982517d6fcebea051ad3d8ec955a3.tar.gz Qt-c7d269eab57982517d6fcebea051ad3d8ec955a3.tar.bz2 |
Fix crash when converting invalid JSValue to string
JSC::JSValue::toString() expects that the input is valid.
Cherry-picked from qt5/qtscript commit
b2969c97fd808e229ff57949dbb9c683f3830b71
Task-number: QTBUG-21896
Change-Id: I534642154ffa4ae400a2ab8e5ce1f0c35899ae6e
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
-rw-r--r-- | src/script/api/qscriptengine_p.h | 2 | ||||
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 9 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index e3aad57..6a023d7 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -1019,6 +1019,8 @@ inline quint16 QScriptEnginePrivate::toUInt16(JSC::ExecState *exec, JSC::JSValue inline JSC::UString QScriptEnginePrivate::toString(JSC::ExecState *exec, JSC::JSValue value) { + if (!value) + return JSC::UString(); JSC::JSValue savedException; saveException(exec, &savedException); JSC::UString str = value.toString(exec); diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 82f4d16..4b6b0b7 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -250,6 +250,7 @@ private slots: void dateRoundtripQtJSQt(); void dateConversionJSQt(); void dateConversionQtJS(); + void stringListFromArrayWithEmptyElement(); }; tst_QScriptEngine::tst_QScriptEngine() @@ -6141,5 +6142,13 @@ void tst_QScriptEngine::scriptValueFromQMetaObject() } } +// QTBUG-21896 +void tst_QScriptEngine::stringListFromArrayWithEmptyElement() +{ + QScriptEngine eng; + QCOMPARE(qscriptvalue_cast<QStringList>(eng.evaluate("[,'hello']")), + QStringList() << "" << "hello"); +} + QTEST_MAIN(tst_QScriptEngine) #include "tst_qscriptengine.moc" |