From df6f587f234249313da5231917437b2b67c28282 Mon Sep 17 00:00:00 2001 From: jiabowen Date: Thu, 16 Jul 2026 16:09:08 +0800 Subject: [PATCH] fix(terminal): make Ctrl+Click work for URLs ending with a port FullUrlRegExp's port group used a consuming boundary check [^0-9], which swallowed the character immediately after the port (newline, space, or '/') into the captured URL string. For URLs like 'http://localhost:8000' at end of a line, the capture became 'http://localhost:8000\n' and QUrl::StrictMode rejected it, so Ctrl+Click silently did nothing while the hover underline still showed. Replace [^0-9] with the non-consuming negative lookahead (?![0-9]). The boundary character is now asserted but not consumed, so the captured URL stays clean and QUrl accepts it. This also fixes a related issue where 'http://localhost:8000/path' was truncated to 'http://localhost:8000/' because the consumed '/' broke the optional path group. Verified against: http://localhost:8000 (was broken), http://localhost:8000/ (works), http://localhost:8000/path (was truncated), http://www.baidu.com:4443/, and invalid port boundary http://localhost:80000 (still rejected as expected). --- 3rdparty/terminalwidget/lib/Filter.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/3rdparty/terminalwidget/lib/Filter.cpp b/3rdparty/terminalwidget/lib/Filter.cpp index 5317244b..4a3f0b3a 100644 --- a/3rdparty/terminalwidget/lib/Filter.cpp +++ b/3rdparty/terminalwidget/lib/Filter.cpp @@ -523,8 +523,11 @@ void UrlFilter::HotSpot::activate(const QString &actionName) /** modify begin by ut001121 zhangmeng 20201215 for 1040-4 Ctrl键+鼠标点击超链接打开网页 */ /** del const QRegularExpression UrlFilter::FullUrlRegExp(QLatin1String("(www\\.(?!\\.)|[a-z][a-z0-9+.-]*://)[^\\s<>'\"]+[^!,\\.\\s<>'\"\\]]"));*/ +// port boundary: (?![0-9]) must stay a non-consuming lookahead. Replacing it +// with [^0-9] swallows the boundary char (newline/space/'/') into the URL and +// QUrl::StrictMode rejects it, so Ctrl+Click on "http://host:port" silently fails. const QRegularExpression UrlFilter::FullUrlRegExp(QLatin1String("(www\\.(?!\\.)|[a-z][a-z0-9+.-]*://)[\\w.@-]+" - "([:]((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([1-9][0-9]{3})|([1-9][0-9]{2})|([1-9][0-9])|([0-9]))[^0-9])?" + "([:]((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([1-9][0-9]{3})|([1-9][0-9]{2})|([1-9][0-9])|([0-9]))(?![0-9]))?" "([/][\\w.@?^=%&/~+#-]+)?")); /** modify end by ut001121 */