Skip to content

UriTemplate expansion reserved ("+") and fragment("#") should not encode already percent encoded parts #2107

Description

@alexander-asenov

According to RFC 6570 Section 3.2.1: reserved ("+") and fragment ("#") expansions allow the set of characters in the union of ( unreserved / reserved / pct-encoded ) to be passed through without pct-encoding, whereas all other expression types allow only unreserved characters to be passed through without pct-encoding.

But currently pct-encoded characters are being re-encoded. Meaning that {+var} and {#var} should not re-encode already pct-encoded triplets, but currently the implementation does that:

Code example

    @Test
    void textUriTemplate_shouldNotEncodeAlreadyPercentEncodedTriplets() {
        String template = "{+var}";
        Map<String, Object> variables = Map.of("var", "admin%2F");

        String result = UriTemplate.expand(template, variables, false);

        // Expecting the result to be "admin%2F" without encoding
        Assertions.assertEquals("admin%2F", result, "The encoded character should not be changed.");
    }
Expected : admin%2F
Actual   : admin%252F

Requested feature:

  • Extend the Level 2 templates support to not re-encode already percent-encoded triplets (e.g., %20 should remain %20) when reserved ("+") and fragment ("#") expansions are used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p2Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions