Is a url query parameter valid if it has no value?

  • Valid to the URI RFC
  • Likely acceptable to your server-side framework/code

The URI RFC doesn’t mandate a format for the query string. Although it is recognized that the query string will often carry name-value pairs, it is not required to (e.g. it will often contain another URI).

3.4. Query

The query component contains non-hierarchical data that, along with
data in the path component (Section 3.3), serves to identify a
resource within the scope of the URI’s scheme and naming authority
(if any). …

… However, as query components
are often used to carry identifying information in the form of
“key=value” pairs and one frequently used value is a reference to
another URI, …

HTML establishes that a form submitted via HTTP GET should encode the form values as name-value pairs in the form “?key1=value1&key2=value2…” (properly encoded). Parsing of the query string is up to the server-side code (e.g. Java servlet engine).

You don’t identify what server-side framework you use, if any, but it is possible that your server-side framework may assume the query string will always be in name-value pairs and it may choke on a query string that is not in that format (e.g. ?bar). If its your own custom code parsing the query string, you simply have to ensure you handle that query string format. If its a framework, you’ll need to consult your documentation or simply test it to see how it is handled.

Leave a Comment