diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 27268f8fc53..0ae2a61db0e 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -888,15 +888,9 @@ void HelpPlugin::activateContext() if (IContext *context = Core::ICore::currentContextObject()) { m_idFromContext = context->contextHelpId(); links = HelpManager::linksForIdentifier(m_idFromContext); - if (links.isEmpty()) { - // Maybe this is already an URL... - // Require protocol specifier, otherwise most strings would be 'local file names' - if (m_idFromContext.contains(QLatin1Char(':'))) { - QUrl url(m_idFromContext); - if (url.isValid()) - links.insert(m_idFromContext, m_idFromContext); - } - } + // Maybe the id is already an URL + if (links.isEmpty() && LocalHelpManager::isValidUrl(m_idFromContext)) + links.insert(m_idFromContext, m_idFromContext); } if (HelpViewer* viewer = viewerForContextMode()) { diff --git a/src/plugins/help/localhelpmanager.cpp b/src/plugins/help/localhelpmanager.cpp index 424bdbe52f4..94bcfe79070 100644 --- a/src/plugins/help/localhelpmanager.cpp +++ b/src/plugins/help/localhelpmanager.cpp @@ -125,6 +125,24 @@ QVariant LocalHelpManager::engineFontSettings() return helpEngine().customValue(Constants::FontKey, QVariant()); } +/*! + * Checks if the string does contain a scheme, and if that scheme is a "sensible" scheme for + * opening in a internal or external browser (qthelp, about, file, http, https). + * This is necessary to avoid trying to open e.g. "Foo::bar" in a external browser. + */ +bool LocalHelpManager::isValidUrl(const QString &link) +{ + QUrl url(link); + if (!url.isValid()) + return false; + const QString scheme = url.scheme(); + return (scheme == QLatin1String("qthelp") + || scheme == QLatin1String("about") + || scheme == QLatin1String("file") + || scheme == QLatin1String("http") + || scheme == QLatin1String("https")); +} + QByteArray LocalHelpManager::helpData(const QUrl &url) { const QHelpEngineCore &engine = helpEngine(); diff --git a/src/plugins/help/localhelpmanager.h b/src/plugins/help/localhelpmanager.h index 6712ae5f98b..7de812d615d 100644 --- a/src/plugins/help/localhelpmanager.h +++ b/src/plugins/help/localhelpmanager.h @@ -58,6 +58,7 @@ public: static BookmarkManager& bookmarkManager(); static QVariant engineFontSettings(); + static bool isValidUrl(const QString &link); Q_INVOKABLE QByteArray helpData(const QUrl &url);