Microsoft/vscode

Markdown URL with text fragment falsely decoded when opening with ctrl + click in editor

Open

#245.128 geöffnet am 31. März 2025

Auf GitHub ansehen
 (0 Kommentare) (1 Reaktion) (2 zugewiesene Personen)TypeScript (10.221 Forks)batch import
bughelp wantedmarkdown-ext

Repository-Metriken

Stars
 (74.848 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 11h 43m) (1.000 gemergte PRs in 30 T)

Beschreibung

Found some more edge cases for #83645 (and related).

To verify

Originally posted by @jrieken in #83645


I tested the following markdown in a new window with code --disable-extensions and Restricted Mode so URLs are shown before opening them in the browser.

![test](https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437)

![test](https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437 "test")

[test](https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437)

[test](https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437 "test")

<https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437>

[test][def]

[def]: https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437

```markdown
![test](https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437)

![test](https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437 "test")

[test](https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437)

[test](https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437 "test")

<https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437>

[test][def]

[def]: https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437
```

When clicking (via ctrl+click) on all links, some don't work:

  • hovering over the links shows a broken image (like:  ), since it falsely links to https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products/zVNZkudXJyq8bPGTXUxx/Betterave-Sesame.jpg?alt%3Dmedia%26token%3D0b2310c4-3ea6-4207-bbde-9c3710ba0437
    • except within the inner code block, which shows nothing on hover (other than "Follow link (ctrl + click)")
  • all (except <...>/all within the inner code block/all in the preview) don't work and falsely decode the URL on opening:
    • to https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products/zVNZkudXJyq8bPGTXUxx/Betterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437

I initially noticed this with the URL https://ffmpeg.org/ffmpeg-all.html#:~:text=%2Dversion, which falsely decodes the %2D in the text fragment (so it doesn't highlight the first -version on the page, which it should), which I thought was the root problem, but turns out that generally the URI/URL parsing was problematic for a long time...

For the edge case specific to the text fragment ~ any %2D after :~:, which is after #, should stay percent encoded (among others, see specs linked below).

https://github.com/WICG/scroll-to-text-fragment#:~:text=dash%20(%2D)%2C,the%20text%20fragment%20syntax

https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Fragment/Text_fragments#:~:text=text%20strings%20used,similarly%20percent%2Dencoded

Anyway, here is another test with more problems:

[test](https://ffmpeg.org/ffmpeg-all.html?test=a%23b%20c#:~:text=%2Dversion)

[test](https://ffmpeg.org/ffmpeg-all.html?test=a%23b%20c#:~:text=%2Dversion "test")

<https://ffmpeg.org/ffmpeg-all.html?test=a%23b%20c#:~:text=%2Dversion>

[test][def]

[def]: https://ffmpeg.org/ffmpeg-all.html?test=a%23b%20c#:~:text=%2Dversion

```markdown
[test](https://ffmpeg.org/ffmpeg-all.html?test=a%23b%20c#:~:text=%2Dversion)

[test](https://ffmpeg.org/ffmpeg-all.html?test=a%23b%20c#:~:text=%2Dversion "test")

<https://ffmpeg.org/ffmpeg-all.html?test=a%23b%20c#:~:text=%2Dversion>

[test][def]

[def]: https://ffmpeg.org/ffmpeg-all.html?test=a%23b%20c#:~:text=%2Dversion
```
  • In the markdown preview, all work but the <...> shows some characters decoded (but still links correctly)
    • shows as https://ffmpeg.org/ffmpeg-all.html?test=a%23b c#:~:text=-version
  • just as before, all (except the <...>/all within the inner code block/all in the preview) fail:
    • warning shows https://ffmpeg.org/ffmpeg-all.html?test=a#b c#:~:text=-version
    • copy from warning gives https://ffmpeg.org/ffmpeg-all.html?test=a%23b c#:~:text=-version
    • opens https://ffmpeg.org/ffmpeg-all.html?test=a%2523b%20c#:~:text=-version in the browser

Contributor Guide