Skip to content

Conversation

@abdellahi-brahim
Copy link

Summary

Fixes #3080

Per RFC 3986 section 4.2, a colon in the first segment of a relative-path reference can be mistaken for a scheme name. For example, user:email={email}/login after parameter substitution becomes user:[email protected]/login, which OkHttp interprets as having a user: scheme.

This PR adds encodeColonInFirstPathSegment() which encodes colons in the first path segment of relative URLs as %3A, preventing the URL resolution from misinterpreting them as URL schemes.

Before:
@put("user:email={email}/login") → Malformed URL error

After:
@put("user:email={email}/login") → http://example.com/user%[email protected]/login

Changes

  • Added encodeColonInFirstPathSegment() helper method in RequestBuilder.java
  • Applied encoding in get() and addQueryParam() methods before URL resolution
  • Added regression tests for colons in path parameters and static URL templates

Test plan

  • Added getWithPathAndQueryColonParam test
  • Added getWithColonInRelativeUrlFirstSegment regression test matching the exact issue scenario
  • All existing tests pass

…gment

Per RFC 3986 section 4.2, a colon in the first segment of a relative-path
reference can be mistaken for a scheme name (e.g., "user:value" looks like
"scheme:authority").

This adds encodeColonInFirstPathSegment() which encodes colons in the first
path segment of relative URLs as %3A, preventing OkHttp's URL resolution
from misinterpreting them as URL schemes.

Fixes square#3080
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.

Invalid Malformed URL

1 participant