UriFormatException when using %40 instead of @ in mailto: protocol

混江龙づ霸主 提交于 2019-12-13 04:41:13

问题


I am writing a default mail client to handle when someone clicks mailto:bob@example.com

craigslist mailto links have the form mailto:bob%40example.com
I get an exception when this is used.
here is some simple code to repeat the problem in c#

System.Uri u1 = new Uri(@"mailto:bob@ms.com");  // ok so far
System.Uri u2 = new Uri(@"http://somewhere.foo/profile/username%40somewhere.foo"); // still ok
System.Uri u3 = new Uri(@"mailto:bob%40ms.com");  // crash here

question 1:
shoudn't mailto:bob%40example.com be a valid uri

question 2:
if it is an invalid uri then how is outlook not crashing on it.

I am using visual studio 2012


回答1:


RFC 6068 (http://www.ietf.org/rfc/rfc6068.txt), which defines the mailto protocol, does not specify that %40 is a valid syntax to replace @ as a username/domain separator.

It does specify that if a username contains a @, such as in the case hello@you@domain.com, you can use %40 to escape it to hello%40you@domain.com. But nowhere does it state that hello%40domain.com would be a valid mailto URI.

And if Microsoft decided to support it in Outlook, that still doesn't change the fact that the RFC, which is authoritative, doesn't define it -- so I'd say, Microsoft probably put it in for reasons of robustness, or maybe it's a side-effect of them parsing any URI for %xx syntax...



来源:https://stackoverflow.com/questions/21039288/uriformatexception-when-using-40-instead-of-in-mailto-protocol

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