Skip to content

fix: hover link encode unnecessarily - #112670

Merged
Alexandru Dima (alexdima) merged 1 commit into
microsoft:masterfrom
chenjigeng:fix/hover-link-encode-unnecessary
Dec 18, 2020
Merged

Alexandru Dima (alexdima) merged 1 commit into
microsoft:masterfrom
chenjigeng:fix/hover-link-encode-unnecessary

Conversation

@chenjigeng

Copy link
Copy Markdown
Contributor

This PR fixes #108819

@chenjigeng

Copy link
Copy Markdown
Contributor Author

The reason for this problem is that if you pass in a URI link, it'll call the toString function to display it .And the toString function of the URI will by default encode.
https://github.com/microsoft/vscode/blob/master/src/vs/base/common/uri.ts#L372

image
image

So is there a need for encode? If not, we can solve this problem by toString(true).

image

@mjbvz Matt Bierner (mjbvz) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing this in core VS Code feels risky since it will effect all languages.

Can you try tracking down why markdown generates a command link that gets corrupted by this encoding?

@alexdima

Copy link
Copy Markdown
Member

The current link.url.toString() was introduced when this feature was added in 1c28c30 by Peng Lyu (@rebornix) .

Johannes Rieken (@jrieken) We need a bit of help here. Here we generate markdown that later on gets clicked on and reaches the opener service. What is the best way to include this link in the markdown? With .toString() or .toString(true) ?

@jrieken

Copy link
Copy Markdown
Contributor

Here we generate markdown that later on gets clicked on and reaches the opener service. What is the best way to include this link in the markdown? With .toString() or .toString(true) ?

The URI unfortunately has bugs that we cannot fix anymore (there are too many extensions relying on these bugs) and therefore links can be a string or URI. So, try to have a string. However, when having a URI it is safe to call toString(true) because it will skip all encoding except for absolutely necessary bits (like # inside the path etc). However, toString(true) might already be too late because the actual bugs in URI are in parse so it really depends on how these uris are created

@alexdima

Copy link
Copy Markdown
Member

OK, then I will accept the PR on the hover side.

But Johannes Rieken (@jrieken) the markdown link provider is stuck with using URI. I think our modes.ts allows for simple strings, but the API only allows URI here

@alexdima

Copy link
Copy Markdown
Member

Thank you chenjg88 (@chenjigeng)

To reproduce:

[example](https://www.example.com?encoded=unnecessarily)

@alexdima
Alexandru Dima (alexdima) merged commit df53f46 into microsoft:master Dec 18, 2020
@jrieken

Copy link
Copy Markdown
Contributor

But Johannes Rieken (@jrieken) the markdown link provider is stuck with using URI. I think our modes.ts allows for simple strings, but the API only allows URI here

Yeah, we have #85930 for that

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

editor-hover Editor mouse hover

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Follow Link tooltip for urls in markdown files encode query string unnecessarily

5 participants