[Mono-dev] [PATCH] System.Uri.EscapeString ()

Stephane Delcroix stephane at delcroix.org
Tue Feb 26 11:26:10 EST 2008


Hey guys,

the System.Uri ctor is sometimes wrong for utf8 strings that need
encoding, as shown is the following code snippet:

<SNIP>
using System;
public class Test
{
        public static void Main()
        {
                string ok = "file:///tmp/x (%232).jpg";
                string nok = "file:///tmp/ü (%232).jpg";

                Console.WriteLine (new Uri (ok).ToString ());
                Console.WriteLine (new Uri (nok).ToString ());
        }
}
<SNAP>

returns:

file:///tmp/x (%232).jpg
file:///tmp/ü (%25232).jpg

which is wrong.

The culprit being the (internal) EscapeString which iterates on a byte[] but check (and then replace) 
for IsHexEncoding on the String itself. For multibyte encodings (like utf8) the index can be out of sync.

I attached a patch, please review.

regards

Stephane
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch
Type: text/x-patch
Size: 2141 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080226/775f304b/attachment.bin 


More information about the Mono-devel-list mailing list