Skip to content

Query encoding isn't RFC3986 compliant #2051

Description

@alienvspredator

The generated code uses Go's standard net/url library for Query parameters encoding. The generated code contains the following line:

queryURL.RawQuery = queryValues.Encode()

Which calls to the func (v url.Values) Encode() string function. This function defined in the Go's standard net/url library isn't fully RFC3986-compliant. RFC3986 states that the space character ' ' (U+0020) has to be encoded as '%20' sequence, while net/url encodes spaces as '+' character. There's an encoding which uses '+' for encoding spaces, but it is a non-standard modification used by browsers to send HTML forms (See: Wikipedia).

While this encoding might be treated as valid by some service providers, there are service providers which expect full compliance with RFC3986 and refuse to serve such requests responding with status 400 Bad Request.

For instance, some OData servers use queries such as ?filter=name eq 'some-name' (encoded as ?filter=name%20eq%20'some-name') and mark ?filter=name+eq+'some-name' as an invalid query.

References:
golang/go#4013
RFC3986
application/x-www-form-urlencoded MIME

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions