From ae31e6e6ace78aea46edbd2f062b69893afcf76c Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 21 Mar 2025 19:19:04 +0100 Subject: [PATCH] Catch invalidly-placed exponents on conversion to C locale Although the number-parsing code to which the C-locale form is later passed was already rejecting such malformed texts, it's better to catch it earlier and to make the check overt in that parsing. Added some tests cases that would fail if this wasn't checked; but they do pass already in the parent. Pick-to: 6.8 6.5 Change-Id: I5ef9e483317ce4dc519ddc7c4c016dcad5cb22c4 Reviewed-by: Dennis Oberst (cherry picked from commit f1d48552e4dfbcdbfd060dd8dd924ae433e7f4c6) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qlocale.cpp | 2 +- tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 5398820916a..542cf9785c9 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -4540,7 +4540,7 @@ bool QLocaleData::numberToCLocale(QStringView s, QLocale::NumberOptions number_o return false; stage = Fraction; } else if (out == 'e') { - if (stage == Name) + if (wantDigits || stage == Name || stage > Fraction) return false; if (stage < Fraction) { diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 448ae037511..f7f058bba8e 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -909,6 +909,9 @@ void tst_QLocale::toReal_data() QTest::newRow("C 1.") << QString("C") << QString("1.") << true << 1.0; QTest::newRow("C 1.E10") << QString("C") << QString("1.E10") << true << 1.0e10; QTest::newRow("C 1e+10") << QString("C") << QString("1e+10") << true << 1.0e+10; + QTest::newRow("C e+10") << QString("C") << QString("e+10") << false << 0.0; + QTest::newRow("C .e+10") << QString("C") << QString(".e+10") << false << 0.0; + QTest::newRow("C 1e+2e+10") << QString("C") << QString("1e+2e+10") << false << 0.0; QTest::newRow("de_DE 1.") << QString("de_DE") << QString("1.") << false << 0.0; QTest::newRow("de_DE 1.2") << QString("de_DE") << QString("1.2") << false << 0.0;