Šime Vidas
Šime Vidas

Reputation: 186103

Is there a difference between a "key" and "key=" URL query string?

For example, when we parse this query string:

foo&bar=&baz=123

Firefox’s implementation of the standard URLSearchParams type (spec) assigns an empty string value to both foo and bar:

enter image description here

Does this mean that foo and foo= are effectively the same inside a query string? Or is it a bug in Firefox?

Upvotes: 1

Views: 725

Answers (1)

lmcarreiro
lmcarreiro

Reputation: 5792

The answer is in the specification in the link that you post...

For each byte sequence bytes in sequences, run these substeps:

  1. If bytes is the empty byte sequence, run these substeps for the next byte sequence.

  2. If bytes contains a =, then let name be the bytes from the start of bytes up to but excluding its first =, and let value be the bytes, if any, after the first = up to the end of bytes. If = is the first byte, then name will be the empty byte sequence. If it is the last, then value will be the empty byte sequence.

  3. Otherwise, let name have the value of bytes and let value be the empty byte sequence

so... key and key= are the same... this is not a bug.

Upvotes: 1

Related Questions