问题
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