Sanic: lost 'PLUS' where parse query string

Created on 2 Jun 2017  Â·  3Comments  Â·  Source: sanic-org/sanic

when the query string include a ‘+’ character, it will be replace by space. E.g.

the URL http://www.example.com/api?val=d+a

when you handler this request, the request.args['val'] will be 'd a'.

It caused by urllib.parse.parse_qs function in Request.py

All 3 comments

Dude, I just click the link in description, it seems to be a porno site, not safe for work...Could you please change it to example.com?

https://httpbin.org/get?val=d+a

{
  "args": {
    "val": "d a"
  }, 
  "headers": {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", 
    "Accept-Encoding": "gzip, deflate, sdch, br", 
    "Accept-Language": "zh-CN,zh;q=0.8", 
    "Connection": "close", 
    "Cookie": "_gauges_unique_hour=1; _gauges_unique_day=1; _gauges_unique_month=1; _gauges_unique_year=1; _gauges_unique=1", 
    "Dnt": "1", 
    "Host": "httpbin.org", 
    "Upgrade-Insecure-Requests": "1", 
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
  }, 
  "origin": "54.92.249.248", 
  "url": "https://httpbin.org/get?val=d+a"
}

I think it's doing the right thing. If you want the '+' in val, it should be url encoded to %2B

https://httpbin.org/get?val=d%2Ba

{
  "args": {
    "val": "d+a"
  }, 
  "headers": {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", 
    "Accept-Encoding": "gzip, deflate, sdch, br", 
    "Accept-Language": "zh-CN,zh;q=0.8", 
    "Connection": "close", 
    "Cookie": "_gauges_unique_hour=1; _gauges_unique_day=1; _gauges_unique_month=1; _gauges_unique_year=1; _gauges_unique=1", 
    "Dnt": "1", 
    "Host": "httpbin.org", 
    "Upgrade-Insecure-Requests": "1", 
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
  }, 
  "origin": "54.92.249.248", 
  "url": "https://httpbin.org/get?val=d%2Ba"
}

Thanks for everyone, I solve it used messense's method. thank you messense.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidtgq picture davidtgq  Â·  3Comments

gsmcwhirter picture gsmcwhirter  Â·  4Comments

geekpy picture geekpy  Â·  4Comments

Souldat picture Souldat  Â·  3Comments

mobdim picture mobdim  Â·  4Comments