Allowing asterisk in URL

给你一囗甜甜゛ 提交于 2019-11-30 21:23:11

http://www.w3.org/Addressing/URL/4_URI_Recommentations.html

Other reserved characters

The asterisk ("*", ASCII 2A hex) and exclamation mark ("!" , ASCII 21 hex) are reserved for use as having special signifiance within specific schemes.

The asterisk (*) is a reserved character with special meaning, so it shouldn't be used incorrectly in URIs. Instead, you should percent encode each username before you insert it into the URI.

Under percent encoding, the asterisk character becomes "%2A".

So the complete, correct URI would be: http://example.com/profile/view/Nice%2A

The percent encoding username should be automatically translated back into the original username string for you.

This will not only allow your URI to validate server-side, but also client-side, when your users copy and paste these addresses into their mail programs.

For example, Stack Overflow automatically hyperlinks the safe, percent encoded URI: http:// example.com/profile/view/Nice%2A

But it doesn't fully hyperlink the unsafe version: http:// example.com/profile/?user=username*

The asterisk is not included in the Stack Overflow link--so your user would have ended up the wrong page.

(Sorry I can't demonstrate this--I'm only allowed to included two links in my post.)

You can save yourself a great deal of trouble by always percent encoding data before you insert it into a URI.

My solution was to change it to a query string.

E.g.:

http://mysite.com/profile/?user=username*

That way it seems to work just fine.

I do know that asterisk (*) is a reserved character and thus I shouldn't even allow usernames to have it. But this solves my problem.

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