none
bug in System.Uri class? RRS feed

  • Question

  • I am trying to write a quick and dirty email client for windows app store but it crashes on craigslist reply links.

    craigslist uses %40 instead of @ sign.

    here is some simple code to repeat problem:

    private void button1_Click(object sender, EventArgs e)
    {
        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
                
    }
     
    Actual code on pastebin.com/tAmwT1Kq

    crash on line 44
    Friday, January 10, 2014 7:22 PM

Answers

  • I would say the workaround would have to be something like this:

    Get the link and use Uri.TryCreate to create a URI

    If successful redirect normally
    If failed and scheme is mailto
        Get the domain info (probably cannot use Uri so you'll likely need to strip off everything between scheme and (? or end of string)
        If domain contains the odd character then replace it with a @ (use UriBuilder if needed to rebuild the URL) and then redirect normally

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Friday, January 10, 2014 10:14 PM
    Moderator

All replies

  • Uri supports the RFC 3987 (with config changes) and the older specs without the config changes.  If you can confirm that the aforementioned URI is valid by the RFC (depending upon which version you're using) then you should report the bug at Connect (http://connect.microsoft.com).  The forums aren't appropriate for reporting framework bugs.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Friday, January 10, 2014 8:10 PM
    Moderator
  • Thanks Michael for getting back so soon,

    I will report the bug, but what I was looking for is a work around.

    If I set Outlook to be the default program for Uri:mailto protocol it works without crashing, so apparently Microsoft has a work around to this "bug".

    Friday, January 10, 2014 10:02 PM
  • I would say the workaround would have to be something like this:

    Get the link and use Uri.TryCreate to create a URI

    If successful redirect normally
    If failed and scheme is mailto
        Get the domain info (probably cannot use Uri so you'll likely need to strip off everything between scheme and (? or end of string)
        If domain contains the odd character then replace it with a @ (use UriBuilder if needed to rebuild the URL) and then redirect normally

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Friday, January 10, 2014 10:14 PM
    Moderator