Skip to content

fix(client): encode query-param spaces as %20 instead of + (#626) - #664

Merged
dakrone merged 2 commits into
dakrone:3.xfrom
jsavyasachi:fix/issue-626-query-space-encoding
Jun 23, 2026
Merged

dakrone merged 2 commits into
dakrone:3.xfrom
jsavyasachi:fix/issue-626-query-space-encoding

Conversation

@jsavyasachi

Copy link
Copy Markdown
Contributor

Fixes #626.

Spaces in :query-params are encoded as + rather than %20. + is correct for an application/x-www-form-urlencoded body, but in the query component of a URI a space should be %20 (RFC 3986); + there is only conventionally - not standardly - read as a space.

generate-query-string is shared by both the form-params (body) and query-params (URI) paths, so the fix is applied only on the query-params path. By that point every literal + is already percent-encoded as %2B, so each remaining + is an encoded space and is rewritten to %20. Form-param bodies are left unchanged.

This also matches the convention already used by url-encode-illegal-characters for raw URL query strings ("Minimizes ambiguity by encoding space to %20").

Tests: query params with spaces -> %20; a literal + value stays %2B; form-param bodies still use +.

URLEncoder encodes a space as +, which is correct for an
application/x-www-form-urlencoded body but not for the query component of a
URI, where a space should be %20 (RFC 3986). generate-query-string is shared
by both the form-params (body) and query-params (URI) paths, so the fix is
applied only on the query-params path: every literal + is already
percent-encoded as %2B at that point, so remaining + characters are encoded
spaces and can be rewritten to %20. Form-param bodies are unchanged. Fixes dakrone#626.
@jsavyasachi

Copy link
Copy Markdown
Contributor Author

Heads-up on CI: this branch targets 3.x, whose workflow is currently broken (see #662). If the checks run before #662 lands they will fail at the Setup java step on infra, not on this change. The change itself is verified locally - full lein with-profile dev,1.10 test :all suite green, 0 reflection warnings in clj-http source - and the matrix passes once #662 is in.

@dakrone dakrone left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks!

@dakrone
dakrone merged commit ebeedce into dakrone:3.x Jun 23, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

URL encoding of whitespace should be "%20" instead of "+" in query parameters

2 participants