-Fixed deserializing relative Uris

This commit is contained in:
James Newton-King
2012-05-30 18:25:16 +12:00
parent 0c8a11b3c1
commit d8017e517b
2 changed files with 20 additions and 1 deletions
@@ -6446,6 +6446,25 @@ Parameter name: value",
Assert.AreEqual("Outter exception...", exception.Message);
}
#endif
[Test]
public void DeserializeRelativeUri()
{
IList<Uri> uris = JsonConvert.DeserializeObject<IList<Uri>>(@"[""http://localhost/path?query#hash""]");
Assert.AreEqual(1, uris.Count);
Assert.AreEqual(new Uri("http://localhost/path?query#hash"), uris[0]);
Uri uri = JsonConvert.DeserializeObject<Uri>(@"""http://localhost/path?query#hash""");
Assert.IsNotNull(uri);
Uri i1 = new Uri("http://localhost/path?query#hash", UriKind.RelativeOrAbsolute);
Uri i2 = new Uri("http://localhost/path?query#hash");
Assert.AreEqual(i1, i2);
uri = JsonConvert.DeserializeObject<Uri>(@"""/path?query#hash""");
Assert.IsNotNull(uri);
Assert.AreEqual(new Uri("/path?query#hash", UriKind.RelativeOrAbsolute), uri);
}
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
@@ -330,7 +330,7 @@ namespace Newtonsoft.Json.Utilities
if (targetType == typeof (Guid))
return new Guid((string) initialValue);
if (targetType == typeof (Uri))
return new Uri((string) initialValue);
return new Uri((string) initialValue, UriKind.RelativeOrAbsolute);
if (targetType == typeof (TimeSpan))
#if !(NET35 || NET20 || SILVERLIGHT || PORTABLE)
return TimeSpan.Parse((string) initialValue, CultureInfo.InvariantCulture);