From 05826cc650616539d8f176b6b1cc126e7185461c Mon Sep 17 00:00:00 2001 From: Simon Redman Date: Thu, 30 May 2019 18:48:14 -0600 Subject: [PATCH] Allow all-zero phone number --- smsapp/conversationlistmodel.cpp | 5 +++++ tests/testconversationlistmodel.cpp | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/smsapp/conversationlistmodel.cpp b/smsapp/conversationlistmodel.cpp index bf1a6017c..5b545a7b5 100644 --- a/smsapp/conversationlistmodel.cpp +++ b/smsapp/conversationlistmodel.cpp @@ -285,5 +285,10 @@ QString ConversationListModel::canonicalizePhoneNumber(const QString& phoneNumbe toReturn = toReturn.remove(')'); toReturn = toReturn.remove('+'); toReturn = toReturn.remove(QRegularExpression("^0*")); // Strip leading zeroes + + if (toReturn.length() == 0) { + // If we have stripped away everything, assume this is a special number (and already canonicalized) + return phoneNumber; + } return toReturn; } diff --git a/tests/testconversationlistmodel.cpp b/tests/testconversationlistmodel.cpp index ce0f712dc..3c0c38367 100644 --- a/tests/testconversationlistmodel.cpp +++ b/tests/testconversationlistmodel.cpp @@ -47,6 +47,7 @@ private Q_SLOTS: void testCzechRepublicShortCodeNonMatch(); void testDifferentPhoneNumbers1(); void testDifferentPhoneNumbers2(); + void testAllZeros(); }; /** @@ -242,5 +243,16 @@ void ConversationListModelTest::testDifferentPhoneNumbers2() "Incorrectly *prefix* matched two phone numbers"); } +/** + * Some places allow a message with all zeros to be a short code. We should allow that too. + */ +void ConversationListModelTest::testAllZeros() +{ + const QString& zeros = QLatin1String("00000"); + const QString& canonicalized = ConversationListModel::canonicalizePhoneNumber(zeros); + + QCOMPARE(canonicalized.length(), zeros.length()); +} + QTEST_MAIN(ConversationListModelTest); #include "testconversationlistmodel.moc"