-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update HttpUrlEncoded.kt #5003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Update HttpUrlEncoded.kt #5003
Conversation
Expose plusIsSpace as an option. Without it, there's no way to decode "+" chars.
WalkthroughThe function Changes
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{kt,kts}
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- CLAUDE.md
**/*.{kt,kts,json,yaml,yml}
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- CLAUDE.md
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: ktorio/ktor#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T08:41:41.935Z
Learning: Prefix commit messages with KTOR-{NUM} (YouTrack issue)
Learnt from: bjhham
PR: ktorio/ktor#4916
File: ktor-server/ktor-server-core/api/ktor-server-core.api:151-151
Timestamp: 2025-06-09T07:08:35.085Z
Learning: Breaking changes are acceptable in Ktor codebase when the code hasn't been released yet, as confirmed by bjhham from the development team.
Learnt from: bjhham
PR: ktorio/ktor#4855
File: ktor-server/ktor-server-plugins/ktor-server-di/api/ktor-server-di.klib.api:334-336
Timestamp: 2025-05-14T18:05:02.321Z
Learning: Breaking changes in constructor parameter order are acceptable for the ktor-server-di module when the code hasn't been released yet, as confirmed by the development team.
Learnt from: tre3p
PR: ktorio/ktor#4936
File: ktor-utils/jvm/src/io/ktor/util/ZstdEncoding.kt:28-35
Timestamp: 2025-06-16T17:03:45.729Z
Learning: In the Ktor codebase, encoder implementations consistently use GlobalScope.writer and GlobalScope.reader patterns for compression/decompression operations. This is the established architectural pattern used throughout the codebase for byte channel transformations.
Learnt from: osipxd
PR: ktorio/ktor#4860
File: ktor-server/ktor-server-plugins/ktor-server-di/api/ktor-server-di.api:24-26
Timestamp: 2025-05-16T13:11:28.416Z
Learning: Binary incompatible changes (such as constructor signature changes) are acceptable in the ktor-server-di module when the version is not yet released, as confirmed by the development team.
🔇 Additional comments (1)
ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt (1)
24-25
: Implementation correctly propagates the plusIsSpace parameter.The parameter is properly passed to both key and value decoding operations, ensuring consistent behavior for the entire parameter parsing process.
@@ -11,7 +11,7 @@ import io.ktor.utils.io.charsets.* | |||
* | |||
* [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.http.parseUrlEncodedParameters) | |||
*/ | |||
public fun String.parseUrlEncodedParameters(defaultEncoding: Charset = Charsets.UTF_8, limit: Int = 1000): Parameters { | |||
public fun String.parseUrlEncodedParameters(defaultEncoding: Charset = Charsets.UTF_8, limit: Int = 1000, plusIsSpace: Boolean = false): Parameters { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Document the new parameter and consider updating the function's KDoc.
The new plusIsSpace
parameter should be documented to explain its purpose and behavior. Additionally, consider updating the existing comment on line 10 since the function can now handle URL encoded forms when plusIsSpace=true
.
Apply this diff to add parameter documentation:
/**
* Parse URL query parameters. Shouldn't be used for urlencoded forms because of `+` character.
+ *
+ * @param defaultEncoding The default character encoding to use
+ * @param limit Maximum number of parameters to parse
+ * @param plusIsSpace Whether to decode '+' characters as spaces
*
* [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.http.parseUrlEncodedParameters)
*/
Consider also updating the main description to reflect the new capability:
/**
- * Parse URL query parameters. Shouldn't be used for urlencoded forms because of `+` character.
+ * Parse URL query parameters. Can optionally handle URL encoded forms when plusIsSpace is true.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
public fun String.parseUrlEncodedParameters(defaultEncoding: Charset = Charsets.UTF_8, limit: Int = 1000, plusIsSpace: Boolean = false): Parameters { | |
/** | |
* Parse URL query parameters. Can optionally handle URL encoded forms when plusIsSpace is true. | |
* | |
* @param defaultEncoding The default character encoding to use | |
* @param limit Maximum number of parameters to parse | |
* @param plusIsSpace Whether to decode '+' characters as spaces | |
* | |
* [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.http.parseUrlEncodedParameters) | |
*/ | |
public fun String.parseUrlEncodedParameters( | |
defaultEncoding: Charset = Charsets.UTF_8, | |
limit: Int = 1000, | |
plusIsSpace: Boolean = false | |
): Parameters { | |
// existing implementation… | |
} |
🤖 Prompt for AI Agents
In ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt at line 14, the new
parameter plusIsSpace in the parseUrlEncodedParameters function is undocumented.
Update the function's KDoc comment above line 14 to include a description of
plusIsSpace, explaining that it controls whether plus signs are interpreted as
spaces during URL decoding. Also revise the main function description to mention
this new capability of handling URL encoded forms when plusIsSpace is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do as the rabbit says here for the documentation ^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjhham I'll implement the documentation changes as suggested by CodeRabbit. Let me update the KDoc to properly document the new plusIsSpace
parameter and revise the function description.
Task: Update KDoc documentation for parseUrlEncodedParameters function
- Update the main function description to reflect new capability with plusIsSpace parameter
- Add proper parameter documentation for all parameters including the new plusIsSpace parameter
- Maintain the existing "Report a problem" link
The documentation will be updated to properly reflect the new functionality and include parameter descriptions as requested. Another agent will implement these changes.
🧠 Learnings used
Learnt from: CR
PR: ktorio/ktor#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T08:41:41.935Z
Learning: Applies to **/*.{kt,kts} : Document all public APIs including parameters, return types, and exceptions
Learnt from: CR
PR: ktorio/ktor#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T08:41:41.935Z
Learning: Prefix commit messages with KTOR-{NUM} (YouTrack issue)
Learnt from: bjhham
PR: ktorio/ktor#4916
File: ktor-server/ktor-server-core/api/ktor-server-core.api:151-151
Timestamp: 2025-06-09T07:08:35.085Z
Learning: Breaking changes are acceptable in Ktor codebase when the code hasn't been released yet, as confirmed by bjhham from the development team.
⏳ Preparing changes...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A summary of the changes CodeRabbit can apply:
- Update the main function description in
HttpUrlEncoded.kt
to include new handling for URL encoded forms with aplusIsSpace
option, and add detailed parameter documentation fordefaultEncoding
,limit
, andplusIsSpace
immediately after the description.
- ✅ Create PR with these edits
- 📌 Create commit in current branch
- 📋 Get copyable edits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
Could you please include a test in io.ktor.tests.http.UrlEncodeTest
And also run
./gradlew apiDump
and commit the API snapshots.
Also, re-target the pull request to the 3.3.0-eap branch.
@@ -11,7 +11,7 @@ import io.ktor.utils.io.charsets.* | |||
* | |||
* [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.http.parseUrlEncodedParameters) | |||
*/ | |||
public fun String.parseUrlEncodedParameters(defaultEncoding: Charset = Charsets.UTF_8, limit: Int = 1000): Parameters { | |||
public fun String.parseUrlEncodedParameters(defaultEncoding: Charset = Charsets.UTF_8, limit: Int = 1000, plusIsSpace: Boolean = false): Parameters { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do as the rabbit says here for the documentation ^
Expose plusIsSpace as an option. Without it, there's no way to decode "+" chars.
Subsystem
Common
Motivation
Improve flexibility with decoding URL encoded parameters.
Solution
Added parameter to the method and propagated it.