Skip to content

Let [=UTF-8 percent-encode=] take an extra optional boolean parameter spaceAsPlus (default false) #765

Closed

Description

@qingxinwu

Is it possible to add an extra boolean parameter spaceAsPlus which defaults to false to UTF-8 percent-encode algorithm? It calls the not exported percent-encode after encoding algorithm which has the spaceAsPlus parameter. For our use case, we want to set spaceAsPlus to true when using [=UTF-8 percent-encode=] algorithm, which is not supported for the algorithm's current defination.

Activity

  1. annevk commented on Mar 22, 2023

    @annevk
    Member

    What is your use case? And why doesn't it use application/x-www-form-urlencoded?

  2. qingxinwu commented on Mar 22, 2023

    @qingxinwu
    Author

    In our code, we encode query params using EscapeQueryParamValue with its use_plus parameter set to true to encode space as "+". It does use application/x-www-form-urlencoded.

    This is the spec that I'd like to use [=UTF-8 percent-encode=]

  3. annevk commented on Mar 22, 2023

    @annevk
    Member

    I guess what I'm wondering is if you can use https://url.spec.whatwg.org/#concept-urlencoded-serializer as entry point, similar to HTML.

    Looking at the callers of what you point to it seems to be inventing its own key/value format with commas instead of ampersands. That's precisely the kind of thing we'd like to avoid.

  4. qingxinwu commented on Mar 22, 2023

    @qingxinwu
    Author

    Sorry, after a closing look, I was wrong about our code using application/x-www-form-urlencoded. It seems it uses component percent-encode set, since EscapeQueryParamValue does not encode !'()~. So I think we cannot use urlencoded-serializer.
    We didn't invent a key/value format. It's still &key=value, but different values of a key are concatenated using commas, e.g., "https://a.com?&key1=value1,value11&key2=value2,value22...".

    I think our use case needs an entry point which calls percent-encode after encoding and allows setting percentEncodeSet to "component percent-encode set" and spaceAsPlus to true. The easist change I can think of is adding spaceAsPlus parameter to [=utf-8 percent-encode=], but not sure if there's any concern, or if there's a better solution.

  5. annevk commented on Mar 22, 2023

    @annevk
    Member

    I mean, that is a new format. Multiple values are encoded by repeating the key in application/x-www-form-urlencoded.

    Since it seems like this is a new technology, it seems like there would still be time to adapt.

  6. qingxinwu commented on Mar 22, 2023

    @qingxinwu
    Author

    Ah I see. Thanks for the clarification!

    1. Are you suggesting that instead of &key1=value1,value2, it should (or better to) be &key1=value1&key1=value2 by standard? Sorry I'm not familiar with this, so not sure how strict the requirement is to follow the latter format.
    2. Besides that, any suggestion on how to spec EscapeQueryParamValue with its use_plus set to true? This is our code, if that's helpful. That is the part that I'm wondering how to document in our spec.
  7. domenic commented on Mar 23, 2023

    @domenic
    Member

    I'd suggest using platform infrastructure as much as you can. This means: (1) yes, use &key1=value1&key1=value2, since that's the standard format; (2) use %20, not +, since that's what the standard does.

  8. MattMenke2 commented on Mar 23, 2023

    @MattMenke2
    Contributor

    Hrm... Using "+" is consistent with what the Javascript URL class does when adding search parameters. Guess that class is over 10 years old, so may not be up to date with the latest best practices. :(

  9. domenic commented on Mar 23, 2023

    @domenic
    Member

    See #491 for that issue :(

  10. annevk commented on Mar 23, 2023

    @annevk
    Member

    I think using https://url.spec.whatwg.org/#concept-urlencoded-serializer and assigning that to URL's query is fine. That gives you +.

    (I think #491 is still inaccurate in that it assumes the key-value format is somehow larger than application/x-www-form-urlencoded. It's not clear we should do that.)

  11. qingxinwu commented on Mar 24, 2023

    @qingxinwu
    Author

    Thanks everyone! We're thinking about changing how we escape our URL query params, and application/x-www-form-urlencoded serializer should work then.

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