summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-04-17 06:21:53 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-04-17 06:21:53 -0700
commit15b970d69eda022112f4ee247de69f34f39d4f47 (patch)
tree44064dea4fcfdc85df93b8eab21493a36023c2c9 /src
parent0cf61f17c975511d56e5584a8da4f1afec250143 (diff)
downloadDotNetOpenAuth-15b970d69eda022112f4ee247de69f34f39d4f47.zip
DotNetOpenAuth-15b970d69eda022112f4ee247de69f34f39d4f47.tar.gz
DotNetOpenAuth-15b970d69eda022112f4ee247de69f34f39d4f47.tar.bz2
Fixed Identifier.TryParse to not throw when passed null or empty string values.
Fixes Trac issue 15.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs16
-rw-r--r--src/DotNetOpenAuth/OpenId/Identifier.cs6
2 files changed, 21 insertions, 1 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs b/src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs
index 2b012dd..53df6c8 100644
--- a/src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs
@@ -19,6 +19,22 @@ namespace DotNetOpenAuth.Test.OpenId {
private string xri = "=arnott*andrew";
[TestMethod]
+ public void TryParseNoThrow() {
+ Identifier id;
+ Assert.IsFalse(Identifier.TryParse(null, out id));
+ Assert.IsFalse(Identifier.TryParse("", out id));
+ }
+
+ [TestMethod]
+ public void TryParse() {
+ Identifier id;
+ Assert.IsTrue(Identifier.TryParse("http://host/path", out id));
+ Assert.AreEqual("http://host/path", id.ToString());
+ Assert.IsTrue(Identifier.TryParse("=arnott", out id));
+ Assert.AreEqual("=arnott", id.ToString());
+ }
+
+ [TestMethod]
public void Parse() {
Assert.IsInstanceOfType(Identifier.Parse(this.uri), typeof(UriIdentifier));
Assert.IsInstanceOfType(Identifier.Parse(this.xri), typeof(XriIdentifier));
diff --git a/src/DotNetOpenAuth/OpenId/Identifier.cs b/src/DotNetOpenAuth/OpenId/Identifier.cs
index 53f5094..1b9570e 100644
--- a/src/DotNetOpenAuth/OpenId/Identifier.cs
+++ b/src/DotNetOpenAuth/OpenId/Identifier.cs
@@ -114,7 +114,11 @@ namespace DotNetOpenAuth.OpenId {
/// True if the operation was successful. False if the string was not a valid OpenId Identifier.
/// </returns>
public static bool TryParse(string value, out Identifier result) {
- Contract.Requires(!string.IsNullOrEmpty(value));
+ if (string.IsNullOrEmpty(value)) {
+ result = null;
+ return false;
+ }
+
if (IsValid(value)) {
result = Parse(value);
return true;