feat(client): escape_path_chars percent-encodes extra characters in path parameters - #122
Merged
Merged
Conversation
…ath parameters Some routers (Rails in particular) end a dynamic path segment at a literal `.` and treat the remainder as a format suffix, so a value such as `acme.example.com-42` only routes when sent as `acme%2Eexample%2Ecom-42`. RFC 3986 leaves `.` unreserved, so the standard escaper never produces that spelling, and pre-encoded input is double-encoded. `Client(; escape_path_chars = ".")` names characters to percent-encode in every path parameter value after the standard escaping. Style delimiters and the template parameter name are left alone, and the option composes with `allowReserved`. `%` is rejected. The default is empty, so existing clients are unchanged. Fixes #120
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #120.
Adds a client-level option that percent-encodes additional characters in path parameter values, on top of the standard RFC 3986 escaping:
Some routers cannot match a literal
.in a dynamic segment (Rails reads it as a format suffix and 404s), but do match%2Ebecause they route on the raw path. RFC 3986 §2.3 makes both spellings the same identifier, so servers that decode before routing are unaffected.Behaviour
simple,label, andmatrixstyles, and forcontent-typed path parameters unless the encoder produced a pre-encoded value..forlabel,;/=formatrix) and the parameter name from the path template are never touched.allowReserved: reserved characters still pass through, listed characters are encoded (a/b.c->a/b%2Ec).%is rejected inescape_path_charswith anArgumentError, since it would re-encode the percent-encoding itself.Changes
src/runtime.jl:Client.escape_path_charsfield and constructor keyword;_percent_encode_chars;escape_charsthreaded through_path_scalar,_path_array,_path_object,_path_parameter, and both path branches of_append_parameter!.test/runtime.jl: unit coverage for each style, delimiter preservation,allowReservedcomposition, and constructor validation.test/runtime_integration.jl: live HTTP check of the wire target with and without the option, and combined withallowReserved.docs/src/clients.md: new "Extra percent-encoding in path parameters" section.MIGRATION.md: maps the 0.2pre_request_hookworkaround to the new option.Tests
julia +1.12 --project=. -e 'using Pkg; Pkg.test()'julia +1.10.11 --project=. -e 'using Pkg; Pkg.test()'