Skip to content

Commit

Permalink
Fix redirect for directories to escape special chars in URL
Browse files Browse the repository at this point in the history
Directories with a "%" in their name do not work correctly when when redirected to a URL with a trailing slash. When the original URl contains special characters, such as "%", the correcponding redirect URL must escape these characters.

Fixes issue ipfs/kubo#10536
  • Loading branch information
gammazero committed Jan 2, 2025
1 parent 85fbc3a commit 16d89a5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ The following emojis are used to highlight certain changes:

### Fixed

- `gateway` Fix links for subdirectories with "%" in name. [#779](https://github.com/ipfs/boxo/pull/779)

### Security


Expand Down
2 changes: 1 addition & 1 deletion gateway/handler_unixfs_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (i *handler) serveDirectory(ctx context.Context, w http.ResponseWriter, r *
suffix = suffix + "?" + r.URL.RawQuery
}
// /ipfs/cid/foo?bar must be redirected to /ipfs/cid/foo/?bar
redirectURL := originalURLPath + suffix
redirectURL := requestURI.EscapedPath() + suffix
rq.logger.Debugw("directory location moved permanently", "status", http.StatusMovedPermanently)
http.Redirect(w, r, redirectURL, http.StatusMovedPermanently)
return true
Expand Down

0 comments on commit 16d89a5

Please sign in to comment.