Skip to content

Flip DefaultQueryEncoder to RFC3986QueryEncoder (space as %20) in v1.10.0 #189

Closed

Description

@mromaszewicz

Follow-up to oapi-codegen/oapi-codegen#2051.

runtime.DefaultQueryEncoder currently defaults to NetURLQueryEncoder, which encodes a space in query parameters as + (Go's net/url / application/x-www-form-urlencoded behavior). Strict RFC 3986 servers (some OData implementations, for example) reject or mis-decode +, and users have to opt in to RFC3986QueryEncoder to get %20.

In v1.10.0 we will flip the default:

var DefaultQueryEncoder QueryEncoder = RFC3986QueryEncoder{}

Rationale:

  • OpenAPI query parameters default to style: form, which is defined in terms of RFC 6570 URI Templates. That expansion encodes a space as %20; + is only part of application/x-www-form-urlencoded, which OpenAPI associates with request bodies, not the query component.
  • %20 is the safer choice: every parser that accepts + as a space also accepts %20, but not the other way around.

This is a change in default client behavior, so it will go out in a minor release and be called out in the release notes. Anyone who depends on the old encoding can restore it at program initialization:

runtime.DefaultQueryEncoder = runtime.NetURLQueryEncoder{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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