From 97b203d0288e127da0eeca141244916166ba5435 Mon Sep 17 00:00:00 2001 From: shanevcantwell <153727980+shanevcantwell@users.noreply.github.com> Date: Fri, 13 Mar 2026 17:01:03 -0600 Subject: [PATCH] fix: terminal links open wrong URL for addresses with ports (#11369) * fix: terminal URL link detection now captures port numbers in IP addresses The link regex was designed for domain names and broke on IP:port URLs like http://192.168.137.1:8081, only linkifying up to the IP without the port. Simplified the http/https branch to match everything after the protocol until whitespace. Closes #11368 Co-Authored-By: Claude Opus 4.6 * test: validate link href attributes in terminal URL test The text-only assertion wouldn't catch a regression where the URL appears in output but the href is truncated (e.g. missing port). Co-Authored-By: Claude Opus 4.6 * style: fix prettier formatting on link regex Co-Authored-By: Claude Opus 4.6 --------- Co-authored-by: Claude Opus 4.6 --- .../UnifiedTerminal/UnifiedTerminal.test.tsx | 11 ++++++++--- .../components/UnifiedTerminal/UnifiedTerminal.tsx | 3 +-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gui/src/components/UnifiedTerminal/UnifiedTerminal.test.tsx b/gui/src/components/UnifiedTerminal/UnifiedTerminal.test.tsx index 55420628f..e6ea5eea8 100644 --- a/gui/src/components/UnifiedTerminal/UnifiedTerminal.test.tsx +++ b/gui/src/components/UnifiedTerminal/UnifiedTerminal.test.tsx @@ -27,7 +27,8 @@ const MOCK_ANSI_OUTPUT = `\u001b[32m✓\u001b[0m Test passed const MOCK_OUTPUT_WITH_LINKS = `Build successful! Visit https://example.com for more info Check www.github.com/user/repo -Error logs at file:///tmp/error.log`; +Error logs at file:///tmp/error.log +Available on: http://192.168.137.1:8081`; // Mock the redux hooks const mockDispatch = vi.fn(); @@ -200,9 +201,13 @@ describe("UnifiedTerminalCommand", () => { // Should contain the link text in the output expect(container.textContent).toMatch(/https:\/\/example\.com/); expect(container.textContent).toMatch(/www\.github\.com/); + expect(container.textContent).toMatch(/http:\/\/192\.168\.137\.1:8081/); - // Note: Link detection might create actual tags or just display the URLs - // The important thing is the URLs are visible in the output + // Verify rendered links have correct hrefs including port + const links = container.querySelectorAll("a"); + const hrefs = Array.from(links).map((a) => a.getAttribute("href")); + expect(hrefs).toContainEqual("https://example.com"); + expect(hrefs).toContainEqual(expect.stringContaining("192.168.137.1:8081")); }); test("shows copy and run in terminal buttons when not running", async () => { diff --git a/gui/src/components/UnifiedTerminal/UnifiedTerminal.tsx b/gui/src/components/UnifiedTerminal/UnifiedTerminal.tsx index f048af8fb..34e72584a 100644 --- a/gui/src/components/UnifiedTerminal/UnifiedTerminal.tsx +++ b/gui/src/components/UnifiedTerminal/UnifiedTerminal.tsx @@ -175,8 +175,7 @@ function convertBundleIntoReact( } const content: React.ReactNode[] = []; - const linkRegex = - /(\s|^)(https?:\/\/(?:www\.|(?!www))[^\s.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/g; + const linkRegex = /(\s|^)(https?:\/\/[^\s]+|www\.[^\s]+\.[^\s]{2,})/g; let index = 0; let match: RegExpExecArray | null;