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 1 commit into
base: main
Choose a base branch
from

Conversation

mattbobambrose
Copy link

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.

Expose plusIsSpace as an option. Without it, there's no way to decode "+" chars.
Copy link
Contributor

coderabbitai bot commented Jul 13, 2025

Walkthrough

The function parseUrlEncodedParameters in the Ktor HTTP module was updated to accept a new Boolean parameter, plusIsSpace, which defaults to false. This parameter determines whether plus signs are interpreted as spaces during URL decoding by being passed to the decoding function for both keys and values.

Changes

File(s) Change Summary
ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt Added plusIsSpace Boolean parameter (default false) to parseUrlEncodedParameters and updated internal decoding calls to use it. Updated function signature accordingly.
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 93d1fde and 56e1874.

📒 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 {
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

Copy link
Contributor

@bjhham bjhham left a 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 {
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 ^

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.

2 participants