diff --git a/src/lib/tools/qztools.cpp b/src/lib/tools/qztools.cpp index 5adecbeb9..518d2eeb3 100644 --- a/src/lib/tools/qztools.cpp +++ b/src/lib/tools/qztools.cpp @@ -195,6 +195,16 @@ QString QzTools::urlEncodeQueryString(const QUrl &url) 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) { const static QString &escapeString = QL1S("!"); diff --git a/src/lib/tools/qztools.h b/src/lib/tools/qztools.h index 94d6d5b63..4f359d37f 100644 --- a/src/lib/tools/qztools.h +++ b/src/lib/tools/qztools.h @@ -46,6 +46,7 @@ public: static QString samePartOfStrings(const QString &one, const QString &other); static QString urlEncodeQueryString(const QUrl &url); + static QString fromPunycode(const QString &str); static QString escapeSqlString(QString urlString); 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); template - static bool containsIndex(const T &container, int index) { + static bool containsIndex(const T &container, int index) + { return (index >= 0 && container.count() > index); } }; diff --git a/src/lib/webkit/webpage.cpp b/src/lib/webkit/webpage.cpp index f4e7d83a0..cc48d977c 100644 --- a/src/lib/webkit/webpage.cpp +++ b/src/lib/webkit/webpage.cpp @@ -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 // It needs to be async to correctly refresh loading state 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; } errorString = tr("Server not found");