1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-14 02:52:12 +01:00

[WebPage] Fix searching for non-ascii one line term from addressbar

The search term (in url) needs to be decoded from punycode.

Closes #1396
This commit is contained in:
David Rosca 2014-06-15 23:30:29 +02:00
parent b48cc71dd5
commit def26ad391
3 changed files with 15 additions and 2 deletions

View File

@ -195,6 +195,16 @@ QString QzTools::urlEncodeQueryString(const QUrl &url)
return returnString; return returnString;
} }
QString QzTools::fromPunycode(const QString &str)
{
if (!str.startsWith(QL1S("xn--")))
return str;
// QUrl::fromAce will only decode domains from idn whitelist
const QString decoded = QUrl::fromAce(str.toUtf8() + QByteArray(".org"));
return decoded.left(decoded.size() - 4);
}
QString QzTools::escapeSqlString(QString urlString) QString QzTools::escapeSqlString(QString urlString)
{ {
const static QString &escapeString = QL1S("!"); const static QString &escapeString = QL1S("!");

View File

@ -46,6 +46,7 @@ public:
static QString samePartOfStrings(const QString &one, const QString &other); static QString samePartOfStrings(const QString &one, const QString &other);
static QString urlEncodeQueryString(const QUrl &url); static QString urlEncodeQueryString(const QUrl &url);
static QString fromPunycode(const QString &str);
static QString escapeSqlString(QString urlString); static QString escapeSqlString(QString urlString);
static QString ensureUniqueFilename(const QString &name, const QString &appendFormat = QString("(%1)")); static QString ensureUniqueFilename(const QString &name, const QString &appendFormat = QString("(%1)"));
@ -88,7 +89,8 @@ public:
static void setWmClass(const QString &name, const QWidget* widget); static void setWmClass(const QString &name, const QWidget* widget);
template <typename T> template <typename T>
static bool containsIndex(const T &container, int index) { static bool containsIndex(const T &container, int index)
{
return (index >= 0 && container.count() > index); return (index >= 0 && container.count() > index);
} }
}; };

View File

@ -767,7 +767,8 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
// If a one-word host was not find, search for the text instead // If a one-word host was not find, search for the text instead
// It needs to be async to correctly refresh loading state // It needs to be async to correctly refresh loading state
if (!exOption->url.host().isEmpty() && !exOption->url.host().contains(QL1C('.'))) { if (!exOption->url.host().isEmpty() && !exOption->url.host().contains(QL1C('.'))) {
QMetaObject::invokeMethod(this, "doWebSearch", Qt::QueuedConnection, Q_ARG(QString, exOption->url.host())); const QString text = QzTools::fromPunycode(exOption->url.host().toUtf8());
QMetaObject::invokeMethod(this, "doWebSearch", Qt::QueuedConnection, Q_ARG(QString, text));
return false; return false;
} }
errorString = tr("Server not found"); errorString = tr("Server not found");