What is the standard for "application / x-www-form-urlencoded" and null?

Some time ago, I noticed that when encoding a name: value map to 'application/x-www-form-urlencoded it displays something similar (here I use Python):

 >>> from urllib import urlencode >>> urlencode({'hello': '', 'blabla': 'hihi'}) 'blabla=hihi&hello=' 

But parsing (at least with Python) just breaks pairs with an empty value:

 >>> from urlparse import parse_qs >>> parse_qs('blabla=hihi&hello=') {'blabla': ['hihi']} 

So ... is this standard behavior? Where can I find a link to how www-form-urlencoded should be analyzed? I have googled for a while, found RFC for uris, W3c docs for forms, etc., but nothing about how empty values ​​should be handled. Can someone give me a pointer to this?

+4
source share
1 answer

As far as I know, there is no "standard" for this. The only thing that is described (in the html specification, as you found out) is how the browser should encode form data. What you want to do (or not) with empty values ​​is up to you.

Note that urlparse.parse_qs() has an optional keep_blank_values parameter that allows you to control how it should handle them:

 >>> from urlparse import parse_qs >>> parse_qs('blabla=hihi&hello=', keep_blank_values=True) {'blabla': ['hihi'], 'hello': ['']} 
+4
source

Source: https://habr.com/ru/post/1342774/


All Articles