Skip to content
Browse files

Fix escaping on relative URI

* System/Uri.cs: While parsing only escape the path for absolute URI.
Do not unescape relative URI in ToString and avoid calling
AppendQueryAndFragment on them (relative) since both are not parsed as
such.

* Test/System/UriTest2.cs: Add test case to show that a relative URI is
NOT escaped by ToString
  • Loading branch information...
1 parent 6ad868a commit 28e93c38d0d7c008bcc594e44771903840d48830 Sebastien Pouliot committed Sep 17, 2010
Showing with 12 additions and 6 deletions.
  1. +5 −6 mcs/class/System/System/Uri.cs
  2. +7 −0 mcs/class/System/Test/System/UriTest2.cs
View
11 mcs/class/System/System/Uri.cs
@@ -1064,14 +1064,14 @@ public override string ToString ()
if (cachedToString != null)
return cachedToString;
- if (isAbsoluteUri)
+ if (isAbsoluteUri) {
cachedToString = Unescape (GetLeftPart (UriPartial.Path), true);
- else {
+ AppendQueryAndFragment (ref cachedToString);
+ } else {
// Everything is contained in path in this case.
- cachedToString = Unescape (path);
+ cachedToString = path;
}
- AppendQueryAndFragment (ref cachedToString);
return cachedToString;
}
@@ -1181,9 +1181,8 @@ private void ParseUri (UriKind kind)
host = host.ToLower (CultureInfo.InvariantCulture);
}
- if (path.Length > 0) {
+ if (isAbsoluteUri && (path.Length > 0))
path = EscapeString (path);
- }
}
#if MOONLIGHT
View
7 mcs/class/System/Test/System/UriTest2.cs
@@ -911,5 +911,12 @@ public void IPv6SafeDnsName ()
Assert.AreEqual ("FE80:0000:0000:0000:0200:39FF:FE36:1A2D%4", uri.DnsSafeHost, "2.DnsSafeHost");
Assert.AreEqual ("[FE80:0000:0000:0000:0200:39FF:FE36:1A2D]", uri.Host, "2.Host");
}
+
+ [Test]
+ public void RelativeEscapes ()
+ {
+ Uri uri = new Uri ("%2e%2e/dir/%2e%2e/subdir/file?query#fragment", UriKind.Relative);
+ Assert.AreEqual ("%2e%2e/dir/%2e%2e/subdir/file?query#fragment", uri.ToString (), "1.ToString");
+ }
}
}

0 comments on commit 28e93c3

Please sign in to comment.
Something went wrong with that request. Please try again.