Skip to content

Commit f270534

Browse files
st0nielzwind
authored andcommitted
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).
1 parent e7bcf81 commit f270534

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

3rdparty/terminalwidget/lib/Filter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,11 @@ void UrlFilter::HotSpot::activate(const QString &actionName)
523523
/** modify begin by ut001121 zhangmeng 20201215 for 1040-4 Ctrl键+鼠标点击超链接打开网页 */
524524
/** del
525525
const QRegularExpression UrlFilter::FullUrlRegExp(QLatin1String("(www\\.(?!\\.)|[a-z][a-z0-9+.-]*://)[^\\s<>'\"]+[^!,\\.\\s<>'\"\\]]"));*/
526+
// port boundary: (?![0-9]) must stay a non-consuming lookahead. Replacing it
527+
// with [^0-9] swallows the boundary char (newline/space/'/') into the URL and
528+
// QUrl::StrictMode rejects it, so Ctrl+Click on "http://host:port" silently fails.
526529
const QRegularExpression UrlFilter::FullUrlRegExp(QLatin1String("(www\\.(?!\\.)|[a-z][a-z0-9+.-]*://)[\\w.@-]+"
527-
"([:]((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])?"
530+
"([:]((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]))?"
528531
"([/][\\w.@?^=%&/~+#-]+)?"));
529532
/** modify end by ut001121 */
530533

0 commit comments

Comments
 (0)