KTOR-2832 Fix URLBuilder(urlString) parsing for schemeless URLs#5395
KTOR-2832 Fix URLBuilder(urlString) parsing for schemeless URLs#5395
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe URLBuilder constructor is redesigned to interpret schemeless strings as host/authority components by prepending "//" before delegating to takeFrom, while special schemes without authority (mailto, data, tel, about) are handled explicitly. Test cases updated to reflect new parsing behavior for schemeless input patterns. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@ktor-http/common/test/io/ktor/tests/http/UrlTest.kt`:
- Around line 368-369: The test currently assumes schemeless input should parse
as null, but parseUrl now treats schemeless strings as hosts; update UrlTest.kt
to reflect the new semantics by replacing the existing assertion with one that
asserts parseUrl("incorrecturl") is not null and that its host equals
"incorrecturl" (use the parseUrl function and the Url/host accessor in the
test), and also add/update the KDoc or a short migration note near the parseUrl
declaration stating that schemeless inputs are interpreted as hosts so callers
relying on null should adjust accordingly.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
ktor-http/common/src/io/ktor/http/URLUtils.ktktor-http/common/test/io/ktor/tests/http/URLBuilderTest.ktktor-http/common/test/io/ktor/tests/http/UrlTest.kt
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When no scheme is present and the input doesn't start with '/',
the URLBuilder factory function now treats the string as an
authority (host with optional port and path) instead of a relative
path. This fixes surprising behavior where URLBuilder("localhost")
produced "http://localhost/localhost" and URLBuilder("localhost:8080")
was parsed with "localhost" as a scheme.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
618577c to
60ec63a
Compare
bjhham
left a comment
There was a problem hiding this comment.
I think this one ought to be targetted for 4.0.0 because it's quite a significant behavioural change which many people may rely on.
The only way I see us mitigating the risk here is if we were to invoke some new logic for guessing whether or not the string looks like a host / authority (checking for localhost or matching on standard TLD's and IP patterns), then defaulting to a path on the negative condition.
|
Agreed — retargeted to |
Actually we don't have a branch to track next major release. I'd not introduce it right now. At least until we polish and automate the process of branch synchronization. |
|
Closing for now — need to resolve branch targeting discussion (no branch for next major release yet). Will revisit when the process is settled. |
Pull request was closed
Summary
URLBuilder(urlString)now treats schemeless strings without a leading/as an authority (host with optional port and path) instead of a relative pathURLBuilder("localhost")producedhttp://localhost/localhost,URLBuilder("google.com")producedhttp://localhost/google.com, andURLBuilder("localhost:8080")parsedlocalhostas a URL schemeKTOR-2832
Test plan
allTests)🤖 Generated with Claude Code