Add a JavaScript utility function for parsing query strings in URLs.

Review Request #9711 — Created March 1, 2018 and submitted

Information

Djblets
release-1.0.x
9f5a114...

Reviewers

This introduces Djblets.parseQueryString(), which will take a query
string or a URL containing one and parse it. It understands key/value
pairs, standalone keys (which will be assigned the value null), and
optionally supports storing multiple values for a key as an array.

Unit tests were added that test all the standard query string cases.

Unit tests pass.

Used this in an upcoming change in Review Board.

Description From Last Updated

, optional?

daviddavid

Given the default value for options, I think you don't need this check and can just use options.allowMultiValue. If someone …

daviddavid

Can we move the decodeURIComponent call into the if/else above?

daviddavid
david
  1. 
      
  2. Show all issues

    , optional?

  3. Show all issues

    Given the default value for options, I think you don't need this check and can just use options.allowMultiValue. If someone passes in something that's falsy and not an object they're using the API wrong.

  4. Show all issues

    Can we move the decodeURIComponent call into the if/else above?

    1. We need to call it in both cases. Might as well only do it once.

    2. It's not like it will ever be called more than once--this is a conditional.

      This is fewer LOC, avoids the multiple-assignment of "key", and is nicer to read IMO:

      if (j === -1) {
          key = decodeURIComponent(queryParam);
          value = null;
      } else {
          key = decodeURIComponent(queryParam.substr(0, j));
          value = decodeURIComponent(queryParam.substr(j + 1));
      }
      
  5. 
      
chipx86
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-1.0.x (438db54)