Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

@coderabbitai coderabbitai bot Jul 13, 2025

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.

Suggested change
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.

Copy link
Contributor

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 ^

Copy link
Contributor

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...

Copy link
Contributor

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 a plusIsSpace option, and add detailed parameter documentation for defaultEncoding, limit, and plusIsSpace immediately after the description.
  • ✅ Create PR with these edits
  • 📌 Create commit in current branch
  • 📋 Get copyable edits

val parameters: List<Pair<String, String>> =
split("&", limit = limit).map { it.substringBefore("=") to it.substringAfter("=", "") }
val encoding: String =
Expand All @@ -21,8 +21,8 @@ public fun String.parseUrlEncodedParameters(defaultEncoding: Charset = Charsets.
return Parameters.build {
parameters.forEach { (key, value) ->
append(
key.decodeURLQueryComponent(charset = charset),
value.decodeURLQueryComponent(charset = charset)
key.decodeURLQueryComponent(charset = charset, plusIsSpace = plusIsSpace),
value.decodeURLQueryComponent(charset = charset, plusIsSpace = plusIsSpace)
)
}
}
Expand Down