Skip to content

Pagination parameters don't encode square brackets; why not? #112

@dmolesUC

Description

@dmolesUC

Per section 12.1.2 of the JSON:API spec, "Square Brackets in Parameter Names",

With query parameter families, JSON:API allows for query parameters whose names contain square brackets (i.e., U+005B “[” and U+005D “]”).

According to the query parameter serialization rules above, a compliant implementation will percent-encode these square brackets. However, some URI producers — namely browsers — do not always encode them.

It looks like in the JSONAPI::Pagination module, not encoding them is a deliberate choice:

links[page_name] = original_url + CGI.unescape(
  original_params.to_query
)

I'm honestly on the fence about this; I mean yes, there's an argument that hypermedia URLs should be opaque, but boy howdy it makes debugging a lot easier when they're not. And the WHATWG URL spec seems to allow square brackets in query strings, even if RFC 3986 doesn't. On the other hand, most Ruby / Rails code follows RFC 3986 (where it's not still on RFC 2396), and also the WHATWG has a reputation for not caring much about APIs.

So this isn't a bug report per se, more a question about what the design intent is here -- I'm trying to implement filters and I'm finding it surprisingly annoying (at least in Ruby / Rails) to generate these URLs with the square brackets intact, so while I'd prefer to be consistent, I'm wondering why / whether it's worth it (and maybe what jsonapi.rb knows that I don't).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions