Block matching empty phone numbers
This commit is contained in:
parent
d4508cd6df
commit
3c346b9409
2 changed files with 19 additions and 0 deletions
|
@ -28,6 +28,11 @@ Q_LOGGING_CATEGORY(KDECONNECT_SMS_SMSHELPER, "kdeconnect.sms.smshelper")
|
||||||
|
|
||||||
bool SmsHelper::isPhoneNumberMatchCanonicalized(const QString& canonicalPhone1, const QString& canonicalPhone2)
|
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:
|
// 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
|
// 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,
|
// 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 testDifferentPhoneNumbers1();
|
||||||
void testDifferentPhoneNumbers2();
|
void testDifferentPhoneNumbers2();
|
||||||
void testAllZeros();
|
void testAllZeros();
|
||||||
|
void testEmptyInput();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -254,5 +255,18 @@ void SmsHelperTest::testAllZeros()
|
||||||
QCOMPARE(canonicalized.length(), zeros.length());
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(SmsHelperTest);
|
QTEST_MAIN(SmsHelperTest);
|
||||||
#include "testsmshelper.moc"
|
#include "testsmshelper.moc"
|
||||||
|
|
Loading…
Reference in a new issue