Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot get request.param if request.body lacks = #245

Open
itsumura-h opened this issue Apr 12, 2020 · 1 comment
Open

cannot get request.param if request.body lacks = #245

itsumura-h opened this issue Apr 12, 2020 · 1 comment

Comments

@itsumura-h
Copy link
Contributor

itsumura-h commented Apr 12, 2020

import uri, httpclient

let data = {
  "name": "",
  "email": "aaa@example.com"
}
echo data.encodeQuery()
>> name&email=aaa%40example.com

var client = newHttpClient()
client.headers = newHttpHeaders({"Content-Type": "application/x-www-form-urlencoded"})
discard client.post("/", body=data.encodeQuery())

If set data in request.body, Jester cannot parse query because query style is not same key=value

# in Jester
echo request.params
>> {"name&email": "aaa@example.com"}

# expected output
>> {"name": "", "email": "aaa@example.com"}
@itsumura-h
Copy link
Contributor Author

itsumura-h commented Apr 13, 2020

https://github.com/dom96/jester/blob/master/jester/private/utils.nim#L23

I think it should be replaced like bellow

proc parseUrlQuery*(query: string, result: var Table[string, string])
    {.deprecated: "use stdlib cgi/decodeData".} =
  for row in query.split("&"):
    if not row.contains("="):
      result[decodeUrl(row)] = ""
    else:
      let rowArr = row.split("=")
      let key = rowArr[0]
      let val = rowArr[1]
      result[decodeUrl(key)] = decodeUrl(val)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant