0

I'm trying to encode a url as an arg value like this

url = "http://test.com?a=1&b=2"
encode_url = "http://domain?url="..ngx.escape_uri(url)

then it became

http://domain?url=http%3A//test.com%3Fa%3D1%26b%3D2

but i want to this

http://domain?url=http%3a%2f%2ftest.com%3fa%3d1%26b%3d2

and I also try ngx.encode_args(), it's the same

Does anyone know why? And how should I do?

pearzl
  • 323
  • 1
  • 2
  • 10
  • [RFC-3986](https://tools.ietf.org/html/rfc3986#section-3.4) recommends *against* escaping `/` in the query. It should be valid either way. Uppercase is also the recommended case for the hex characters in percent-escapes. – Michael - sqlbot Sep 12 '17 at 02:25
  • @Michael-sqlbot Thank you very much. – pearzl Sep 12 '17 at 06:25

1 Answers1

0
host = "http://test.com"
uri = "?a=1&b=2"

encode_host = ngx.encode_args({[host]=true})
encode_args = ngx.escape_uri(uri)
encode_url = "http://domain?url=" .. encode_host .. encode_args
  • 4
    While this may answer the question, you should [edit] your answer to include a bit of context or explanation for why this answers the question. An answer containing only a code block is not immediately useful for anyone who comes across the same issue later on. – Hoppeduppeanut Apr 18 '19 at 10:11