Allow all-zero phone number
This commit is contained in:
parent
a5a0c16b61
commit
05826cc650
2 changed files with 17 additions and 0 deletions
|
@ -285,5 +285,10 @@ QString ConversationListModel::canonicalizePhoneNumber(const QString& phoneNumbe
|
||||||
toReturn = toReturn.remove(')');
|
toReturn = toReturn.remove(')');
|
||||||
toReturn = toReturn.remove('+');
|
toReturn = toReturn.remove('+');
|
||||||
toReturn = toReturn.remove(QRegularExpression("^0*")); // Strip leading zeroes
|
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;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ private Q_SLOTS:
|
||||||
void testCzechRepublicShortCodeNonMatch();
|
void testCzechRepublicShortCodeNonMatch();
|
||||||
void testDifferentPhoneNumbers1();
|
void testDifferentPhoneNumbers1();
|
||||||
void testDifferentPhoneNumbers2();
|
void testDifferentPhoneNumbers2();
|
||||||
|
void testAllZeros();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -242,5 +243,16 @@ void ConversationListModelTest::testDifferentPhoneNumbers2()
|
||||||
"Incorrectly *prefix* matched two phone numbers");
|
"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);
|
QTEST_MAIN(ConversationListModelTest);
|
||||||
#include "testconversationlistmodel.moc"
|
#include "testconversationlistmodel.moc"
|
||||||
|
|
Loading…
Reference in a new issue