Skip to content

Commit

Permalink
fix: urls don't encode characters
Browse files Browse the repository at this point in the history
When a file url has certain symbols like number sign (#), it doesn't encode them, which makes the browser fail to navigate to the file, thinking it is a document section. This commit fixes that by encoding urls using the built-in encodeURIComponent function.

Fixes vercel#120, vercel#205, vercel/serve#726, and vercel/serve#774
  • Loading branch information
abubakriz committed Jul 31, 2024
1 parent 17f3f7e commit 6fa2cfa
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/directory.jst
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@
<i>Index of&nbsp;</i>

{{~it.paths :value:index}}
<a href="/{{!value.url}}">{{!value.name}}</a>
<a href="/{{!encodeURIComponent(value.url)}}">{{!value.name}}</a>
{{~}}
</h1>
</header>

<ul id="files">
{{~it.files :value:index}}
<li>
<a href="{{!value.relative}}" title="{{!value.title}}" class="{{!value.type}} {{!value.ext}}">{{!value.base}}</a>
<a href="{{!encodeURIComponent(value.relative)}}" title="{{!value.title}}" class="{{!value.type}} {{!value.ext}}">{{!value.base}}</a>
</li>
{{~}}
</ul>
Expand Down

0 comments on commit 6fa2cfa

Please sign in to comment.