sindresorhus / terminal-link

Create clickable links in the terminal
MIT License
620 stars 25 forks source link

Clickable links including "zero width space" in URL #18

Open Soviut opened 2 years ago

Soviut commented 2 years ago

I've already reported this issue on the Netlify CLI repo https://github.com/netlify/cli/issues/4311

I'm using VSCode and am working on a project that uses the Netlify CLI. They print out the URLs to the serverless functions as they're loaded. These URLs include a "zero width space" (U+200B).

◈ Loaded function api (​http://localhost:8888/.netlify/functions/api​).
◈ Loaded function render (​http://localhost:8888/.netlify/functions/render​).

Clicking those links in the VSCode terminal includes the zero width space, producing URLs that look like

http://localhost:8888/.netlify/functions/api%E2%80%8B

I know there is a fallback that adds the character for unsupported terminals. VSCode isn't specifically on the support list, but it can also use lots of different terminals so it may be listed as one of them. Even if none are supported, VSCode's terminal seems to make any URL-like string clickable, for example:

image

I'm curious if it would be safe for me to write a PR for the Netlify CLI that turns it off or returns a normal space?

kbrandwijk commented 2 years ago

We have observed this same behavior in Github Action logs, the URL is displayed in fallback mode (text (url)) but the URL when clicked includes the zero width space.

jackiewmacharia commented 2 years ago

Defining a fallback function is a possible workaround for this e.g. terminalLink(text, url, { fallback: () => `${text} ${url}` })