Commit 3c346b94 authored by Simon Redman's avatar Simon Redman

Block matching empty phone numbers

parent d4508cd6
Pipeline #4119 passed with stage
in 8 minutes and 53 seconds
......@@ -28,6 +28,11 @@ Q_LOGGING_CATEGORY(KDECONNECT_SMS_SMSHELPER, "kdeconnect.sms.smshelper")
bool SmsHelper::isPhoneNumberMatchCanonicalized(const QString& canonicalPhone1, const QString& canonicalPhone2)
if (canonicalPhone1.isEmpty() || canonicalPhone2.isEmpty()) {
// The empty string is not a valid phone number so does not match anything
return false;
// To decide if a phone number matches:
// 1. Are they similar lengths? If two numbers are very different, probably one is junk data and should be ignored
// 2. Is one a superset of the other? Phone number digits get more specific the further towards the end of the string,
......@@ -48,6 +48,7 @@ private Q_SLOTS:
void testDifferentPhoneNumbers1();
void testDifferentPhoneNumbers2();
void testAllZeros();
void testEmptyInput();
......@@ -254,5 +255,18 @@ void SmsHelperTest::testAllZeros()
QCOMPARE(canonicalized.length(), zeros.length());
* An empty string is not a valid phone number and should not match anything
void SmsHelperTest::testEmptyInput()
const QString& empty = QLatin1String("");
const QString& shortCode = QLatin1String("44455");
const QString& realNumber = QLatin1String("12223334444");
QVERIFY2(!SmsHelper::isPhoneNumberMatch(empty, shortCode), "The empty string matched a shortcode phone number");
QVERIFY2(!SmsHelper::isPhoneNumberMatch(empty, realNumber), "The empty string matched a real phone number");
#include "testsmshelper.moc"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment