Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
[libcontacts] Ensure search terms are trimmed
When searching for merge candidates, trim the strings used as search
tokens in case they contain problematic whitespace.
  • Loading branch information
matthewvogt committed Jun 19, 2014
1 parent 03168e5 commit 4884893
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions src/seasidecache.cpp
Expand Up @@ -1271,33 +1271,35 @@ static QContactFilter filterForMergeCandidates(const QContact &contact)
QContactFilter rv;

QContactName name(contact.detail<QContactName>());
const QString firstName(name.firstName());
const QString lastName(name.lastName());
const QString firstName(name.firstName().trimmed());
const QString lastName(name.lastName().trimmed());

if (firstName.isEmpty() && lastName.isEmpty()) {
// Use the displayLabel to match with
QString label(contact.detail<QContactDisplayLabel>().label());

// Partial match to first name
QContactDetailFilter firstNameFilter;
setDetailType<QContactName>(firstNameFilter, QContactName::FieldFirstName);
firstNameFilter.setMatchFlags(QContactFilter::MatchContains | QContactFilter::MatchFixedString);
firstNameFilter.setValue(label);
rv = rv | firstNameFilter;

// Partial match to last name
QContactDetailFilter lastNameFilter;
setDetailType<QContactName>(lastNameFilter, QContactName::FieldLastName);
lastNameFilter.setMatchFlags(QContactFilter::MatchContains | QContactFilter::MatchFixedString);
lastNameFilter.setValue(label);
rv = rv | lastNameFilter;

// Partial match to nickname
QContactDetailFilter nicknameFilter;
setDetailType<QContactNickname>(nicknameFilter, QContactNickname::FieldNickname);
nicknameFilter.setMatchFlags(QContactFilter::MatchContains | QContactFilter::MatchFixedString);
nicknameFilter.setValue(label);
rv = rv | nicknameFilter;
const QString label(contact.detail<QContactDisplayLabel>().label().trimmed());

if (!label.isEmpty()) {
// Partial match to first name
QContactDetailFilter firstNameFilter;
setDetailType<QContactName>(firstNameFilter, QContactName::FieldFirstName);
firstNameFilter.setMatchFlags(QContactFilter::MatchContains | QContactFilter::MatchFixedString);
firstNameFilter.setValue(label);
rv = rv | firstNameFilter;

// Partial match to last name
QContactDetailFilter lastNameFilter;
setDetailType<QContactName>(lastNameFilter, QContactName::FieldLastName);
lastNameFilter.setMatchFlags(QContactFilter::MatchContains | QContactFilter::MatchFixedString);
lastNameFilter.setValue(label);
rv = rv | lastNameFilter;

// Partial match to nickname
QContactDetailFilter nicknameFilter;
setDetailType<QContactNickname>(nicknameFilter, QContactNickname::FieldNickname);
nicknameFilter.setMatchFlags(QContactFilter::MatchContains | QContactFilter::MatchFixedString);
nicknameFilter.setValue(label);
rv = rv | nicknameFilter;
}
} else {
if (!firstName.isEmpty()) {
// Partial match to first name
Expand Down Expand Up @@ -1342,7 +1344,7 @@ static QContactFilter filterForMergeCandidates(const QContact &contact)

// Phone number match
foreach (const QContactPhoneNumber &phoneNumber, contact.details<QContactPhoneNumber>()) {
const QString number(phoneNumber.number());
const QString number(phoneNumber.number().trimmed());
if (number.isEmpty())
continue;

Expand All @@ -1351,11 +1353,11 @@ static QContactFilter filterForMergeCandidates(const QContact &contact)

// Email address match
foreach (const QContactEmailAddress &emailAddress, contact.details<QContactEmailAddress>()) {
QString address(emailAddress.emailAddress());
QString address(emailAddress.emailAddress().trimmed());
int index = address.indexOf(QChar::fromLatin1('@'));
if (index > 0) {
// Match any address that is the same up to the @ symbol
address = address.left(index);
address = address.left(index).trimmed();
}

if (address.isEmpty())
Expand All @@ -1370,11 +1372,11 @@ static QContactFilter filterForMergeCandidates(const QContact &contact)

// Account URI match
foreach (const QContactOnlineAccount &account, contact.details<QContactOnlineAccount>()) {
QString uri(account.accountUri());
QString uri(account.accountUri().trimmed());
int index = uri.indexOf(QChar::fromLatin1('@'));
if (index > 0) {
// Match any account URI that is the same up to the @ symbol
uri = uri.left(index);
uri = uri.left(index).trimmed();
}

if (uri.isEmpty())
Expand Down

0 comments on commit 4884893

Please sign in to comment.