summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-03-28 18:52:55 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2010-03-30 21:38:27 -0700
commit959c14042acbbd9921ca0147f8f70f13bda5650a (patch)
tree95a83e5b4f86eb498756fa92db9837806e623209 /src
parent84343fa08e8f386aeb353cd8b2300c767fb43069 (diff)
downloadDotNetOpenAuth-959c14042acbbd9921ca0147f8f70f13bda5650a.zip
DotNetOpenAuth-959c14042acbbd9921ca0147f8f70f13bda5650a.tar.gz
DotNetOpenAuth-959c14042acbbd9921ca0147f8f70f13bda5650a.tar.bz2
Added escaping normalization for Path part in SimpleUri class.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs5
-rw-r--r--src/DotNetOpenAuth/OpenId/UriIdentifier.cs18
2 files changed, 23 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs b/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs
index 5dbaa4a..0c51ac1 100644
--- a/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs
@@ -271,9 +271,14 @@ namespace DotNetOpenAuth.Test.OpenId {
Assert.AreEqual("http://abc/D./e.?Qq#Ff", new UriIdentifier.SimpleUri("HTTP://ABC/D./e.?Qq#Ff").ToString());
Assert.AreEqual("http://abc/D./e.?Qq", new UriIdentifier.SimpleUri("HTTP://ABC/D./e.?Qq").ToString());
Assert.AreEqual("http://abc/D./e.#Ff", new UriIdentifier.SimpleUri("HTTP://ABC/D./e.#Ff").ToString());
+ Assert.AreEqual("http://abc/", new UriIdentifier.SimpleUri("HTTP://ABC/").ToString());
Assert.AreEqual("http://abc/", new UriIdentifier.SimpleUri("HTTP://ABC").ToString());
Assert.AreEqual("http://abc/?q", new UriIdentifier.SimpleUri("HTTP://ABC?q").ToString());
Assert.AreEqual("http://abc/#f", new UriIdentifier.SimpleUri("HTTP://ABC#f").ToString());
+
+ Assert.AreEqual("http://abc/a//b", new UriIdentifier.SimpleUri("http://abc/a//b").ToString());
+ Assert.AreEqual("http://abc/a%2Fb/c", new UriIdentifier.SimpleUri("http://abc/a%2fb/c").ToString());
+ Assert.AreEqual("http://abc/A/c", new UriIdentifier.SimpleUri("http://abc/%41/c").ToString());
}
private static void TestAsFullAndPartialTrust(Action<bool> action) {
diff --git a/src/DotNetOpenAuth/OpenId/UriIdentifier.cs b/src/DotNetOpenAuth/OpenId/UriIdentifier.cs
index c1eb837..9f2c646 100644
--- a/src/DotNetOpenAuth/OpenId/UriIdentifier.cs
+++ b/src/DotNetOpenAuth/OpenId/UriIdentifier.cs
@@ -535,6 +535,8 @@ namespace DotNetOpenAuth.OpenId {
this.Path = value.Substring(hostFinish, pathFinish - hostFinish);
}
}
+
+ this.Path = NormalizePathEscaping(this.Path);
}
/// <summary>
@@ -576,6 +578,22 @@ namespace DotNetOpenAuth.OpenId {
public override string ToString() {
return this.Scheme + Uri.SchemeDelimiter + this.Authority + this.Path + this.Query + this.Fragment;
}
+
+ /// <summary>
+ /// Normalizes the characters that are escaped in the given URI path.
+ /// </summary>
+ /// <param name="path">The path to normalize.</param>
+ /// <returns>The given path, with exactly those characters escaped which should be.</returns>
+ private static string NormalizePathEscaping(string path) {
+ Contract.Requires<ArgumentNullException>(path != null);
+
+ string[] segments = path.Split('/');
+ for (int i = 0; i < segments.Length; i++) {
+ segments[i] = Uri.EscapeDataString(Uri.UnescapeDataString(segments[i]));
+ }
+
+ return string.Join("/", segments);
+ }
}
/// <summary>