Skip to content

Incorrect expansion of multiple query variables #108

Closed as not planned
Closed as not planned
@phodopus42

Description

@phodopus42

Version: 4.1.1. Platform: Fedora 37 x86_64 (though this is not platform dependant).

tl;dr: With multiple query variables, URITemplate appends a ? instead of a &. This is in violation of RFC6570 (IIUC).

Expected:

>>> URITemplate("http://example.org{?foo}{?bar}").expand(foo="this", bar="that")
'http://example.org?foo=this&bar=that'

(Second variable has a continuation.)

Actual:

>>> URITemplate("http://example.org{?foo}{?bar}").expand(foo="this", bar="that")
'http://example.org?foo=this?bar=that'

(Second variable has a question mark -- incorrect.)

See https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.8

For each defined variable in the variable-list:

o append "?" to the result string if this is the first defined value
or append "&" thereafter;

The form {&foo} is only for those templates that have a literal ?. See https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.9

Form-style query continuation, as indicated by the ampersand ("&")
operator in Level 3 and above templates, is useful for describing
optional &name=value pairs in a template that already contains a
literal query component with fixed parameters.

I can provide a patch later if required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions