Should a browser encode a custom URI before launching an app?

情到浓时终转凉″ 提交于 2019-12-12 18:34:11

问题


I have an app which gets launched on a custom URI which looks like myapp://whatever/something

There is a HTML page which has a href link as this -> myapp://whatever/?x=abc;y=pqr; When this is clicked in chrome, myapp gets the URL myapp://whatever/?x=abc%3By%3Dpqr%3B, the URL gets encoded However when I click on the same link on the default Internet browser - no encoding is done. It gets the original URL -> myapp://whatever/?x=abc;y=pqr;

What is the correct behavior?

I tried this using Chrome 38.0.2125.114 on Android 4.4.3. Also, I think earlier versions of Chrome didn't do this, but not so sure.


回答1:


Treatment of semicolons in URLs isn't totally consistent, so your best approach is to escape your URL correctly and unambiguously.

If you intend to set a single query parameter of x to the value abc;y=pqr; then the escaped form is correct:

?x=abc%3By%3Dpqr%3B

However, if you intend separate parameters then & would be a better choice for interoperability. If you want to specify x as abc and y as pqr then you should specify this as:

?x=abc&y=pqr

As you've seen, browser behaviour is not predictable with unescaped semicolons, so avoid them.



来源:https://stackoverflow.com/questions/26707046/should-a-browser-encode-a-custom-uri-before-launching-an-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!