diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index b50d5901e0c..7a8623dc254 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -4082,7 +4082,8 @@ double QByteArray::toDouble(bool *ok) const auto QtPrivate::toDouble(QByteArrayView a) noexcept -> ParsedNumber { - auto r = qt_asciiToDouble(a.data(), a.size(), WhitespacesAllowed); + a = a.trimmed(); + auto r = qt_asciiToDouble(a.data(), a.size()); if (r.ok()) return ParsedNumber{r.result}; else diff --git a/tests/auto/corelib/text/qbytearrayapisymmetry/tst_qbytearrayapisymmetry.cpp b/tests/auto/corelib/text/qbytearrayapisymmetry/tst_qbytearrayapisymmetry.cpp index f03086342ce..f8343c8806b 100644 --- a/tests/auto/corelib/text/qbytearrayapisymmetry/tst_qbytearrayapisymmetry.cpp +++ b/tests/auto/corelib/text/qbytearrayapisymmetry/tst_qbytearrayapisymmetry.cpp @@ -1497,9 +1497,18 @@ template void tst_QByteArrayApiSymmetry::toFloat() const QCOMPARE(ByteArray().toFloat(&ok), 0.0f); QVERIFY(!ok); + ok = true; QCOMPARE(ByteArray("").toFloat(&ok), 0.0f); QVERIFY(!ok); + ok = true; + QCOMPARE(ByteArray(" ").toFloat(&ok), 0.0f); + QVERIFY(!ok); + + ok = true; + QCOMPARE(ByteArray(" ").toFloat(&ok), 0.0f); + QVERIFY(!ok); + // NB: floats < 1e-6 are zero as far as QCOMPARE() is concerned ! const char data[] = "0.0000931322574615478515625"; const float expectedValue = 9.31322574615478515625e-5f; @@ -1523,6 +1532,8 @@ void tst_QByteArrayApiSymmetry::toDouble_data() const QTest::newRow("null") << QByteArray() << 0.0 << false; QTest::newRow("empty") << QByteArray("") << 0.0 << false; + QTest::newRow("space-only") << QByteArray(" ") << 0.0 << false; + QTest::newRow("spaces-only") << QByteArray(" ") << 0.0 << false; QTest::newRow("decimal") << QByteArray("1.2345") << 1.2345 << true; QTest::newRow("exponent lowercase") << QByteArray("1.2345e+01") << 12.345 << true; diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 80f83519571..cfc0ec1cc07 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -7622,8 +7622,10 @@ void tst_QString::double_conversion_data() // The bad... + QTest::newRow("C null") << QString() << false << 0.0; QTest::newRow("C empty") << u""_s << false << 0.0; - QTest::newRow("C null") << QString() << false << 0.0; + QTest::newRow("C space") << u" "_s << false << 0.0; + QTest::newRow("C spaces") << u" "_s << false << 0.0; QTest::newRow("C .") << u"."_s << false << 0.0; QTest::newRow("C 1e") << u"1e"_s << false << 0.0; QTest::newRow("C 1,") << u"1,"_s << false << 0.0;