Path parameter having special characters like brackets and parentheses is not encoded properly in retrofit2
I am from Spinnaker community. We have recently migrated some of our services from retrofit1 to retrofit2. We have hundreds of apis overall. After migration we are facing challenges with path parameter encoding.
With retrofit1, the path param [foo] b:ar (baz) used to be encoded to %5Bfoo%5D%20b%3Aar%20%28baz%29 and api has no issues.
But after migrating to retrofit2, the encoded value became [foo]%20b:ar%20(baz) and api rejects it with 400.
Is there any plan to fix this issue? What is the work around you suggest?
RFC 3986 section 3.3 defines a path as comprised of pchars:
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
which then references
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
So we are not required to encode parenthesis, but are supposed to encode square brackets.
However, this behavior is inherited from OkHttp which current does not encode square brackets per https://github.com/square/okhttp/issues/6790. Since we are built OkHttp, we inherit its behavior. Now technically that's not true for path encoding as we copy OkHttp's implementation, but otherwise use its HttpUrl.Builder to construct HTTP URLs. The illusion is that we use OkHttp's HttpUrl.Builder for everything, however, so I would prefer to align with its behavior.
Perhaps you could plead your case on their issue, and then once OkHttp changes we will change as well.
Is this related to my issue here? We upgraded from Spinnaker 1.36.1 (retrofit 1.x) to 1.37.6 (retrofix 2.x). After this upgrade, we noticed any Spinnaker pipeline with square brackets [ ] wasn't being encoded correctly, and our jobs won't run. Downgrading to 1.36.1 fixed the issue.