3

if I have a query string like:

?key1=val1&key2==val2

how it should be parsed?

like:

key   : key2= 
value : val2

or

key   : key2 
value : =val2

what would be the key and the value in this case?

Is this allowed to have == sequencies in query string?

And what about following query strings?

?key=val&=====

is that syntactically correct?

Thanks

6
  • 1
    I think in practice it's going to depend on what you want to use them for. Commented Jan 29, 2015 at 17:47
  • 2
    I never tried it but i think if you try to read the key2 you will get =vale2. Commented Jan 29, 2015 at 17:51
  • I don't know about syntax rules, but I would definitely recommend against it. What are you trying to accomplish? Commented Jan 29, 2015 at 17:52
  • Judging from PHP implementation (SAPI.treat_data, used by both parse_str and in the internal params parsing), = symbol is always treated as the one separating the keys and values, and system-level separator (usually &) is used to separate the pairs. So in your first case, key2 will be the key, and =val2 will be the value. In your second case, the last series of ===== will be just ignored, as there's no key to extract there. Commented Jan 29, 2015 at 18:10
  • I'm not sure, however, that all the query parser implementations follow the same routine. And it's up to implementation, as w3 only provides a recommendation of how to build a query string (source). Commented Jan 29, 2015 at 18:10

1 Answer 1

2

I think you're likely to run into implementation-specific behavior if you try to use query strings like that, but at least as far as .NET's HttpUtility.ParseQueryString() goes, the breakdown would be:

key1=val1&key2==val2

key1 - val1
key2 - =val2


key=val&=====

key - val
    - ====     (key is blank, value is four =)

So this is basically equivalent to splitting the query string on & and then splitting each of those segments on the first =.

Sign up to request clarification or add additional context in comments.

1 Comment

Same behavior in Java servlets (HttpServletRequest.getParameter())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.