Skip to content

[Rust][Reqwest] Utilise percent-encoding for path params when using reqwest - #25258

Merged
wing328 merged 4 commits into
OpenAPITools:masterfrom
GlenWright:rust-reqwest-path-param-space-encoding
Nov 4, 2026
Merged

wing328 merged 4 commits into
OpenAPITools:masterfrom
GlenWright:rust-reqwest-path-param-space-encoding

Conversation

@GlenWright

@GlenWright GlenWright commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes path parameter space encoding by modifying the urlencode fn to use percent-encoding in reqwest and reqwest-trait. They were originally sent as + as opposed to %20.

To more closely match previous behaviour, everything except unreserved characters is encoded, RFC3986 refers.

I've also added percent-encoding to Cargo.toml (incl. manually maintained ones), a codegen test and regenerated the samples.

Fixes #25257.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@frol @farcaller @richardwhiuk @paladinzh @jacob-pro @dsteeley


Summary by cubic

Fixes a bug in the generated Rust reqwest and reqwest-trait clients where spaces in path parameters were encoded as + instead of %20, breaking URL paths with spaces.

  • Replaces the urlencode helper's form_urlencoded::byte_serialize implementation with percent_encoding::utf8_percent_encode, using a PATH_ENCODING_SET that percent-encodes all reserved characters per RFC3986 while keeping unreserved characters (-, ., _, ~) untouched. This preserves the previous encoding behavior for other reserved characters while fixing spaces.
  • Adds the percent-encoding dependency to generated Cargo.toml files, a codegen test covering both libraries, and regenerated samples.

Written for commit fc4a3f7. Summary will update on new commits.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 27 files

View guided diff | Re-trigger cubic

@GlenWright

Copy link
Copy Markdown
Contributor Author

Had a quick skim of the logs, looks like it failed because of a network issue:

Could not GET 'https://github.com/JetBrains/kotlin/releases/download/v2.0.21/kotlin-compiler-embeddable-2.0.21.jar'. Received status code 500 from server: Internal Server Error


pub fn urlencode<T: AsRef<str>>(s: T) -> String {
::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect::<String>().replace("+", "%20")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR. what about using https://docs.rs/percent-encoding/latest/percent_encoding/ instead ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this but was unsure if an additional dependency would be preferable. It seems like the more robust solution, so I'll revise shortly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the PR to use percent_encoding, and modified accordingly per review comments.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 50 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@GlenWright GlenWright changed the title [Rust][Reqwest] Correctly encode spaces in path params when using reqwest [Rust][Reqwest] Utilise percent-encoding for path params when using reqwest Oct 28, 2026
@wing328 wing328 added this to the 7.28.0 milestone Nov 4, 2026
@wing328
wing328 merged commit 784b623 into OpenAPITools:master Nov 4, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][RUST] Reqwest - encoding of spaces in path parameters

2 participants