Repository navigation
fix: percent-encode spaces in request path URLs - #887
sylvesterkaczmarek wants to merge 2 commits into
Conversation
20de775 to
6df04ee
Compare
|
Following up after the Group 6 maintenance pass. This branch is current with main, mergeable, and has no failing checks or unresolved review threads. It has been open for over six weeks without maintainer feedback. Could a maintainer review it when convenient? |
agammann
left a comment
There was a problem hiding this comment.
I reviewed the two-file diff. URLEncoder uses form encoding, so replacing its + only for path segments maps spaces to %20; a literal plus has already become %2B before that replacement. The new tests cover both values, and the existing query-parameter case confirms that form encoding still uses + there. This looks consistent with the intended URL behavior. I did not run tests locally.
|
Thanks for reviewing the URL encoding change, @agammann. I kept the patch scoped to path rendering so the existing form-encoded query behavior and OkHttp request construction remain unchanged. The two-file diff is still mergeable. I couldn't rerun Gradle tests here because this Mac has no Java runtime, so that validation remains outstanding. Appreciate the careful review. |
Summary
Make
HttpRequest.url()encode spaces in path segments as%20instead of+, matching URL path semantics and the URL actually constructed by the OkHttp transport.Fixes #886.
Problem
HttpRequest.url()currently usesURLEncoderfor both path segments and query parameters.For query parameters, form encoding is appropriate and a space becomes
+.For path segments, however,
+is a literal plus character. A request containing:.addPathSegment("user name")currently renders as:
The OkHttp transport itself constructs the request with
HttpUrl.Builder.addPathSegment, so the actual wire URL uses:LoggingHttpClientprintsrequest.url(), which means SDK logs can show a different request target from the one actually sent.Fix
Keep the existing
URLEncoderbehavior for query components, but normalize the encoded path-segment space representation:A literal plus remains unambiguous because
URLEncoderalready encodes it as%2Bbefore the replacement is applied.Regression coverage
Updated
HttpRequestTestto verify:%20;+path character renders as%2B;hello+world.Validation
mainatcf942a40074291290634321ad9fe21e514030b4c;HttpRequest.kt;Full repository validation is left to GitHub Actions.
Risk
Low. This changes only the diagnostic/string rendering of path-segment spaces. Query encoding and transport request construction are unchanged.