Skip to content

Commit

Permalink
-Fixed deserializing relative Uris
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed May 30, 2012
1 parent 0c8a11b commit d8017e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6446,6 +6446,25 @@ public void DeserializeException()
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)
Expand Down
2 changes: 1 addition & 1 deletion Src/Newtonsoft.Json/Utilities/ConvertUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public static object Convert(object initialValue, CultureInfo culture, Type targ
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);
Expand Down

0 comments on commit d8017e5

Please sign in to comment.