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

request help: apisix hmac url paramater encode result not equal java ecnode result #5690

Closed
liangliang4ward opened this issue Dec 4, 2021 · 5 comments

Comments

@liangliang4ward
Copy link
Contributor

liangliang4ward commented Dec 4, 2021

Issue description

image
like this:apisix + replace to '%20' ,but in java is "%2B",use URLEncode.ecnode.
"2021-10 00:01" apisix encode result is "2021-10%2000%3A01",bust in java is "2021-10+00%3A01"

I want to know how to use java to generate

Environment

  • apisix version (cmd: apisix version): 2.10.2
  • OS (cmd: uname -a):
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V):
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API):
  • apisix-dashboard version, if have:
  • the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner):
  • luarocks version, if the issue is about installation (cmd: luarocks --version):
@tzssangglass
Copy link
Member

In fact, APISIX uses [ngx.escape_uri](https://github.com/openresty/lua-nginx-module#ngxescape_uri) to escape uri, this way the + is translated into a space, I hope this is useful to you: https://www.cnblogs.com/zhengxl5566/p/10783422.html
refer to:
[1]: openresty/lua-nginx-module#1124
[2]: https://juejin.cn/post/6844903512485134343#heading-6
[3]: https://www.cnblogs.com/zhengxl5566/p/10783422.html

@liangliang4ward
Copy link
Contributor Author

In fact, APISIX uses [ngx.escape_uri](https://github.com/openresty/lua-nginx-module#ngxescape_uri) to escape uri, this way the + is translated into a space, I hope this is useful to you: https://www.cnblogs.com/zhengxl5566/p/10783422.html refer to: [1]: openresty/lua-nginx-module#1124 [2]: https://juejin.cn/post/6844903512485134343#heading-6 [3]: https://www.cnblogs.com/zhengxl5566/p/10783422.html

+ apisix is %20 but in java is %2B
space apisix is %20 but in java is +
! apisix is ! but in java is %21
# apisix is %24 but in java is %23
% apisix is % but in java is %25
( apisix is ( but in java is %28
')' apisix is ) but in java is %29

I don't thin use replace is good idea

@liangliang4ward
Copy link
Contributor Author

may be like this
String value = URLEncoder.encode(Optional.ofNullable(param.getValue()).orElse(""), "utf-8")
.replaceAll("\%2B","%20")
.replaceAll("\+","%20")
.replaceAll("\%21","!")
.replaceAll("\%27","'")
.replaceAll("\%28","(")
.replaceAll("\%29",")")
.replaceAll("\%7E","~")
.replaceAll("\%25","%")
;

@tzssangglass
Copy link
Member

It's barely okay. I think you could look for some generic class libraries, like guava.

@tzssangglass
Copy link
Member

@qq54903099 can we close this issue now?

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

2 participants