summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-11-18 14:26:58 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2022-11-24 10:06:53 +0100
commit6c435e5dd41177308f22ba4b55931b2c463cb0d8 (patch)
treecd607b37ec21b3c6bb2bfa5862c0e4bc2dc4d44b /tests/auto/corelib
parenta036bd1746a8be9d8d9f15d70f8d0258d1a4fc46 (diff)
Restore end-of-parse reporting to qstrntod()
Rework QSimpleParsedNumber to store a qsizetype whose sign serves as ok flag (positive is ok, zero and negative are not) and magnitude is the number of characters used. This replaces an endptr that was set to null to indicate !ok, but that deprived us of end-of-parse information, which is needed for number-parsing. In particular, JS's parsing of numbers accepts overflow (where qstrntod() flags it as invalid) as infinity; so qstrntod() does need to say how long the overflowing (but JS-valid, none the less) number-text was. Modify all callers of functions using this (recently-introduced) type and add tests that fail without this fix. Fixes: QTBUG-108628 Change-Id: I416cd213e1fb8101b1af5a6d43615b970a5db9b4 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/text/qlocale/tst_qlocale.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
index f29b8a96ff..593b98dd60 100644
--- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
@@ -1246,6 +1246,10 @@ void tst_QLocale::strtod_data()
QTest::newRow("12456789012") << QString("12456789012") << 12456789012.0 << 11 << true;
QTest::newRow("1.2456789012e10") << QString("1.2456789012e10") << 12456789012.0 << 15 << true;
+ // Overflow - fails but reports right length:
+ QTest::newRow("1e2000") << QString("1e2000") << qInf() << 6 << false;
+ QTest::newRow("-1e2000") << QString("-1e2000") << -qInf() << 7 << false;
+
// starts with junk, fails
QTest::newRow("a0") << QString("a0") << 0.0 << 0 << false;
QTest::newRow("a0.") << QString("a0.") << 0.0 << 0 << false;
@@ -1277,6 +1281,10 @@ void tst_QLocale::strtod_data()
QTest::newRow("12456789012f") << QString("12456789012f") << 12456789012.0 << 11 << true;
QTest::newRow("1.2456789012e10g") << QString("1.2456789012e10g") << 12456789012.0 << 15 << true;
+ // Overflow, ends with cruft - fails but reports right length:
+ QTest::newRow("1e2000 cruft") << QString("1e2000 cruft") << qInf() << 6 << false;
+ QTest::newRow("-1e2000 cruft") << QString("-1e2000 cruft") << -qInf() << 7 << false;
+
// "0x" prefix, success but only for the "0" before "x"
QTest::newRow("0x0") << QString("0x0") << 0.0 << 1 << true;
QTest::newRow("0x0.") << QString("0x0.") << 0.0 << 1 << true;
@@ -1309,9 +1317,9 @@ void tst_QLocale::strtod()
QCOMPARE(actualOk, ok);
QCOMPARE(static_cast<int>(end - numData.constData()), processed);
- // make sure neither QByteArray, QString or QLocale also work
- // (but they don't support incomplete parsing)
- if (processed == num_str.size() || processed == 0) {
+ // Make sure QByteArray, QString and QLocale also work.
+ // (They don't support incomplete parsing, and give 0 for overflow.)
+ if (ok && (processed == num_str.size() || processed == 0)) {
actualOk = false;
QCOMPARE(num_str.toDouble(&actualOk), num);
QCOMPARE(actualOk, ok);