Skip to content

Commit

Permalink
core: Fix contact ID parsing with new URI name
Browse files Browse the repository at this point in the history
Regression from 3f3b857, which prevented adding new contacts.
  • Loading branch information
special committed Jul 6, 2014
1 parent 8d1d7a4 commit 131d8e5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/core/ContactIDValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "ContactIDValidator.h"

static QRegularExpression regex(QStringLiteral("(torsion|ricochet):[a-z2-7]{16}"));
static QRegularExpression regex(QStringLiteral("(torsion|ricochet):([a-z2-7]{16})"));

ContactIDValidator::ContactIDValidator(QObject *parent)
: QRegularExpressionValidator(parent), m_uniqueIdentity(0)
Expand Down Expand Up @@ -72,7 +72,7 @@ ContactUser *ContactIDValidator::matchingContact(const QString &text) const

bool ContactIDValidator::matchesIdentity(const QString &text) const
{
return m_uniqueIdentity && m_uniqueIdentity->contactID() == text;
return m_uniqueIdentity && m_uniqueIdentity->hostname() == hostnameFromID(text);
}

void ContactIDValidator::fixup(QString &text) const
Expand All @@ -87,10 +87,11 @@ bool ContactIDValidator::isValidID(const QString &text)

QString ContactIDValidator::hostnameFromID(const QString &ID)
{
if (!isValidID(ID))
QRegularExpressionMatch match = regex.match(ID);
if (!match.hasMatch())
return QString();

return ID.mid(8) + QStringLiteral(".onion");
return match.captured(2) + QStringLiteral(".onion");
}

QString ContactIDValidator::idFromHostname(const QString &hostname)
Expand Down

0 comments on commit 131d8e5

Please sign in to comment.