[Mono-list] Problem with URI
John Anderson
sontek at gmail.com
Sun Sep 16 21:06:16 EDT 2007
On 9/16/07, John Anderson <sontek at gmail.com> wrote:
>
> Right now unix paths are being accepted as a valid absolute path, but in
> ms.net the path "/test.aspx" is relative
>
> and since there is no real way to differentiate between the 2 I suggest we
> force unixpaths to have file:// on them
> or we can do a specific check when passing UriKind.Relative to accept
> rooted locations like /test.aspx
we talked about it on IRC and my suggested fix would break code like:
new Uri(System.IO.Path.GetFullPath("test/test.aspx"))
so I think we should go the route of just checking if UriKind is passed as
Relative:
heres the new patch:
Index: System/Uri.cs
===================================================================
--- System/Uri.cs (revision 85855)
+++ System/Uri.cs (working copy)
@@ -90,9 +90,11 @@
private string cachedToString;
private string cachedLocalPath;
private int cachedHashCode;
-
+
private static readonly string hexUpperChars =
"0123456789ABCDEF";
-
+#if NET_2_0
+ private UriKind uriKind;
+#endif
// Fields
public static readonly string SchemeDelimiter = "://";
@@ -125,6 +127,7 @@
public Uri (string uriString, UriKind uriKind)
{
source = uriString;
+ this.uriKind = uriKind;
ParseUri ();
switch (uriKind) {
@@ -1263,7 +1266,11 @@
+ "determined.");
} else if (pos < 0) {
// It must be Unix file path or Windows UNC
+#if NET_2_0
+ if (uriString [0] == '/' && uriKind !=
UriKind.Relative)
+#else
if (uriString [0] == '/')
+#endif
ParseAsUnixAbsoluteFilePath
(uriString);
else if (uriString.Length >= 2 && uriString
[0] == '\\' && uriString [1] == '\\')
ParseAsWindowsUNC (uriString);
and I'd also suggest adding a test for this:
Index: Test/System/UriTest.cs
===================================================================
--- Test/System/UriTest.cs (revision 85855)
+++ Test/System/UriTest.cs (working copy)
@@ -1182,6 +1182,12 @@
Assert ("#5b", !uri3.Equals(uri4));
}
+ [Test]
+ public void RootedRelativePath()
+ {
+ Uri uri1 = new Uri ("/test.aspx", UriKind.Relative);
+ Assert ("#1", uri1.IsAbsoluteUri == false);
+ }
[ExpectedException(typeof(InvalidOperationException))]
[Test]
public void GetLeftPart_Partial1 ()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20070916/ed9bc7de/attachment-0001.html
More information about the Mono-list
mailing list