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 <noreply@anthropic.com> * 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 <a> href is truncated (e.g. missing port). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style: fix prettier formatting on link regex Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ac1fd3634d
commit
97b203d028
2 changed files with 9 additions and 5 deletions
|
|
@ -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 <a> 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 () => {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue