From: Charles Yin Date: Tue, 6 Sep 2011 03:54:46 +0000 (+1000) Subject: more fixes for QTBUG-17868 X-Git-Tag: qt-v5.0.0-alpha1~1733 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0fdd97f613af6ae255e9cd1470ad8d4d67091dd7;p=profile%2Fivi%2Fqtdeclarative.git more fixes for QTBUG-17868 QDeclarativePropertyCache bypasses the previous fix, need to check the property name when property cache try to create property. Change-Id: Ibccc02df568a8ded3626bb914150ba9ee87d238f Task-number:QTBUG-17868 Reviewed-on: http://codereview.qt.nokia.com/4230 Reviewed-by: Qt Sanity Bot Reviewed-by: Michael Brasser --- diff --git a/src/declarative/util/qdeclarativepropertymap.cpp b/src/declarative/util/qdeclarativepropertymap.cpp index c924267..fc009a8 100644 --- a/src/declarative/util/qdeclarativepropertymap.cpp +++ b/src/declarative/util/qdeclarativepropertymap.cpp @@ -58,7 +58,7 @@ public: protected: virtual void propertyWritten(int index); virtual void propertyCreated(int, QMetaPropertyBuilder &); - + virtual int createProperty(const char *, const char *); private: QDeclarativePropertyMap *map; QDeclarativePropertyMapPrivate *priv; @@ -71,8 +71,19 @@ public: QDeclarativePropertyMapMetaObject *mo; QStringList keys; void emitChanged(const QString &key, const QVariant &value); + bool validKeyName(const QString& name); }; +bool QDeclarativePropertyMapPrivate::validKeyName(const QString& name) +{ + //The following strings shouldn't be used as property names + return name != QLatin1String("keys") + && name != QLatin1String("valueChanged") + && name != QLatin1String("QObject") + && name != QLatin1String("destroyed") + && name != QLatin1String("deleteLater"); +} + void QDeclarativePropertyMapPrivate::emitChanged(const QString &key, const QVariant &value) { Q_Q(QDeclarativePropertyMap); @@ -95,6 +106,13 @@ void QDeclarativePropertyMapMetaObject::propertyCreated(int, QMetaPropertyBuilde priv->keys.append(QString::fromUtf8(b.name())); } +int QDeclarativePropertyMapMetaObject::createProperty(const char *name, const char *value) +{ + if (!priv->validKeyName(name)) + return -1; + return QDeclarativeOpenMetaObject::createProperty(name, value); +} + /*! \class QDeclarativePropertyMap \brief The QDeclarativePropertyMap class allows you to set key-value pairs that can be used in QML bindings. @@ -181,12 +199,8 @@ QVariant QDeclarativePropertyMap::value(const QString &key) const void QDeclarativePropertyMap::insert(const QString &key, const QVariant &value) { Q_D(QDeclarativePropertyMap); - //The following strings shouldn't be used as property names - if (key != QLatin1String("keys") - && key != QLatin1String("valueChanged") - && key != QLatin1String("QObject") - && key != QLatin1String("destroyed") - && key != QLatin1String("deleteLater")) { + + if (d->validKeyName(key)) { d->mo->setValue(key.toUtf8(), value); } else { qWarning() << "Creating property with name" diff --git a/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp b/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp index 5583701..966ac19 100644 --- a/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp +++ b/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp @@ -61,6 +61,7 @@ private slots: void count(); void crashBug(); + void QTBUG_17868(); }; void tst_QDeclarativePropertyMap::insert() @@ -218,6 +219,23 @@ void tst_QDeclarativePropertyMap::crashBug() delete obj; } +void tst_QDeclarativePropertyMap::QTBUG_17868() +{ + QDeclarativePropertyMap map; + + QDeclarativeEngine engine; + QDeclarativeContext context(&engine); + context.setContextProperty("map", &map); + map.insert("key", 1); + QDeclarativeComponent c(&engine); + c.setData("import QtQuick 2.0\nItem {property bool error:false; Component.onCompleted: {try{console.log(map.keys());}catch(e) {error=true;}}}",QUrl()); + QObject *obj = c.create(&context); + QVERIFY(obj); + QVERIFY(!obj->property("error").toBool()); + delete obj; + +} + QTEST_MAIN(tst_QDeclarativePropertyMap) #include "tst_qdeclarativepropertymap.moc"