diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index daaba5334..f35bb1bf6 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -6446,6 +6446,25 @@ public void DeserializeException() Assert.AreEqual("Outter exception...", exception.Message); } #endif + + [Test] + public void DeserializeRelativeUri() + { + IList uris = JsonConvert.DeserializeObject>(@"[""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(@"""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(@"""/path?query#hash"""); + Assert.IsNotNull(uri); + Assert.AreEqual(new Uri("/path?query#hash", UriKind.RelativeOrAbsolute), uri); + } } #if !(SILVERLIGHT || NETFX_CORE || PORTABLE) diff --git a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs index 59e6c836f..25286a8f8 100644 --- a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs @@ -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);