Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(routing/http/client): avoid escaping comma query separator #688

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

- `routing/http/client`: optional address and protocol filter parameters from [IPIP-484](https:/ipfs/specs/pull/484) use human-readable `,` instead of `%2C`. [#688](https:/ipfs/boxo/pull/688)

### Security

## [v0.24.0]
Expand Down
8 changes: 7 additions & 1 deletion routing/http/filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ func AddFiltersToURL(baseURL string, protocolFilter, addrFilter []string) string
query.Set("filter-addrs", strings.Join(addrFilter, ","))
}

parsedURL.RawQuery = query.Encode()
// The comma is in the "sub-delims" set of characters that don't need to be
// encoded in most parts of a URL, including query parameters. Golang
// standard library percent-escapes it for consistency, but we prefer
// human-readable /routing/v1 URLs, and real comma is restored here to
// ensure human and machine requests hit the same HTTP cache keys.
parsedURL.RawQuery = strings.ReplaceAll(query.Encode(), "%2C", ",")

return parsedURL.String()
}

Expand Down
6 changes: 3 additions & 3 deletions routing/http/filters/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ func TestAddFiltersToURL(t *testing.T) {
baseURL: "https://example.com/routing/v1/providers/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi",
protocolFilter: []string{"transport-bitswap", "transport-ipfs-gateway-http"},
addrFilter: nil,
expected: "https://example.com/routing/v1/providers/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi?filter-protocols=transport-bitswap%2Ctransport-ipfs-gateway-http",
expected: "https://example.com/routing/v1/providers/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi?filter-protocols=transport-bitswap,transport-ipfs-gateway-http",
},
{
name: "Only addr filter",
baseURL: "https://example.com/routing/v1/providers/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi",
protocolFilter: nil,
addrFilter: []string{"ip4", "ip6"},
expected: "https://example.com/routing/v1/providers/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi?filter-addrs=ip4%2Cip6",
expected: "https://example.com/routing/v1/providers/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi?filter-addrs=ip4,ip6",
},
{
name: "Both filters",
baseURL: "https://example.com/routing/v1/providers/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi",
protocolFilter: []string{"transport-bitswap", "transport-graphsync-filecoinv1"},
addrFilter: []string{"ip4", "ip6"},
expected: "https://example.com/routing/v1/providers/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi?filter-addrs=ip4%2Cip6&filter-protocols=transport-bitswap%2Ctransport-graphsync-filecoinv1",
expected: "https://example.com/routing/v1/providers/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi?filter-addrs=ip4,ip6&filter-protocols=transport-bitswap,transport-graphsync-filecoinv1",
},
{
name: "URL with existing query parameters",
Expand Down