ngx.escape_uri() didn't work on '/'?

1.2k views Asked by At

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?

1

There are 1 answers

1
user6785777 On
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