diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2018-04-23 14:40:58 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2018-04-24 07:41:17 +0000 |
commit | 501bb599bfcfa7b98227f7fc295cd8e0a09bc927 (patch) | |
tree | 6bda5fc4eb7e44f58d118bb9397ac3e6ae4e321c /src/lib/corelib/tools/settingsrepresentation.cpp | |
parent | 3653385af94ae7fe042d1c4845293b495bdc9854 (diff) |
Command line parser: Don't accidentally create floating-point values
This could easily happen; e.g. a property assignment such as "version:
10.10" would result in the version property getting the value "10.1".
While users could work around that, the behavior was rather surprising.
We claim that no floating-point values are ever assigned to properties
and force such values to get parsed as strings.
Task-number: QBS-1242
Change-Id: I0e21cefaed11de1553cb3ed085280adfb489a1a7
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/lib/corelib/tools/settingsrepresentation.cpp')
-rw-r--r-- | src/lib/corelib/tools/settingsrepresentation.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib/corelib/tools/settingsrepresentation.cpp b/src/lib/corelib/tools/settingsrepresentation.cpp index f977fbd9f..256c60c0e 100644 --- a/src/lib/corelib/tools/settingsrepresentation.cpp +++ b/src/lib/corelib/tools/settingsrepresentation.cpp @@ -64,7 +64,14 @@ static QVariant variantFromString(const QString &str, bool &ok) QVariant representationToSettingsValue(const QString &representation) { bool ok; - const QVariant variant = variantFromString(representation, ok); + QVariant variant = variantFromString(representation, ok); + + // We have no floating-point properties, so this is most likely intended to be a string. + if (static_cast<QMetaType::Type>(variant.type()) == QMetaType::Float + || static_cast<QMetaType::Type>(variant.type()) == QMetaType::Double) { + variant = variantFromString(QLatin1Char('"') + representation + QLatin1Char('"'), ok); + } + if (ok) return variant; |