Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty URI query string parameters: "a=&b=" versus "a&b"

Tags:

http

url

Should the following URLs be considered functionally equivalent?

http://example.com/foo?a=&b=

http://example.com/foo?a&b

This came about when a user of a Drupal module I wrote which parses apart and then rewrites URIs noticed that the code sometimes causes the query string parts to change in unexpected ways due to how some of the underlying PHP functions behave. For example:

parse_str("a&b", $values); print http_build_query($values);

a=&b=

Is this something I should bother worrying about?

Edit so SO stops complaining that this question is similar to another one: The question is whether it's safe to assume that "no value for X" and "empty value for X" are equivalent, not whether the "no value" style is syntactically correct (which it is).

like image 432
Garrett Albright Avatar asked Mar 25 '12 23:03

Garrett Albright


People also ask

Can query parameters be empty?

Yes, it is valid. If one simply want to check if the parameter exists or not, this is one way to do so. Save this answer.

How do you pass an empty query parameter?

How To Send A Request With Empty Query Parameters? To mark a parameter as required, you need to go to the Request editor on the API tab and check the Required checkbox. Please see the below screenshot. After this, ReadyAPI will generate the required URL.

What are URI parameters and query parameters?

A URI parameter identifies a specific resource whereas a Query Parameter is used to sort or filter resources.

Can URI have query parameters?

URI parameter (Path Param) is basically used to identify a specific resource or resources whereas Query Parameter is used to sort/filter those resources. Let's consider an example where you want identify the employee on the basis of employeeID, and in that case, you will be using the URI param.


1 Answers

RFC 3986 Uniform Resource Identifier (URI): Generic Syntax doesn't have anything to say about the structure of the query string aside from how characters like ? should be dealt with. So strictly speaking, your two example URLs are different. Of course, the application which receives those query strings may treat them as functionally equivalent, but this isn't something you can determine from the URL alone.

like image 120
Paul Dixon Avatar answered Sep 21 '22 20:09

Paul Dixon