1

I have a requirement of adding multiple nested paths in the querystring. For which, im encoding the individual path names and combine those with / (delimiter). If a path contains slash in it, that will be encoded as %2F..However we are not encoding delimiter slash(which is used for spliting the path)

example:

Input1: a->b->c Input 2: path_with_/_slash->d->e

Output: ?q=a/b/c+path_with_%2F_slash/d/e

Note: im creating querystring manually (not using urlsearchparams, as it encodes all the slashed including the separator)

Is it ok to use unencoded slash (used as separator) in query string? Will that create any problem in any of the browsers? Is there a better way to handle this scenario?

saranya
  • 9
  • 2

1 Answers1

1

If you're manually forming the query string, you must follow the procedure outlined in the URL Standard, section 5.2, "application/x-www-form-urlencoded serializing":

  1. Let output be the empty string.
  2. For each tuple of tuples:
    1. Let name be the result of running percent-encode after encoding with encoding, tuple’s name, the application/x-www-form-urlencoded percent-encode set, and true.
    2. Let value be the result of running percent-encode after encoding with encoding, tuple’s value, the application/x-www-form-urlencoded percent-encode set, and true.
    3. If output is not the empty string, then append U+0026 (&) to output.
    4. Append name, followed by U+003D (=), followed by value, to output.
  3. Return output.

And unless you hand-rolled your own server, any functions/middleware/etc. for working with url queries during route handling will have automatically urldecoded those values for you.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153