Skip to content

Commit 3e1dea2

Browse files
Fixing Uri when a relative uri is added to an absolute one and the separator is missing (#472)
Co-authored-by: José Simões <[email protected]>
1 parent 7a41d99 commit 3e1dea2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Tests/HttpUnitTests/UriUnitTests.cs

+16
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ public void UriCtor_Should_Not_Throw_Exception(string uri)
9090
Assert.IsNotNull(createdUri);
9191
}
9292

93+
[DataRow("http://user:[email protected]/Home", "Index.html?q1=v1&q2=v2#FragmentName", "http://user:[email protected]/Home/Index.html?q1=v1&q2=v2#FragmentName")]
94+
[DataRow("http://user:[email protected]/Home/", "Index.html?q1=v1&q2=v2#FragmentName", "http://user:[email protected]/Home/Index.html?q1=v1&q2=v2#FragmentName")]
95+
[DataRow("http://user:[email protected]/Home", "/Index.html?q1=v1&q2=v2#FragmentName", "http://user:[email protected]/Home/Index.html?q1=v1&q2=v2#FragmentName")]
96+
[DataRow("http://user:[email protected]/Home/", "/Index.html?q1=v1&q2=v2#FragmentName", "http://user:[email protected]/Home/Index.html?q1=v1&q2=v2#FragmentName")]
97+
public void UriWithParamaters(string uri, string paramaters, string correctFullUri)
98+
{
99+
Uri baseUri = new(uri);
100+
Uri fullUri = new(correctFullUri);
101+
Uri parmUri = new(paramaters, UriKind.Relative);
102+
Uri finalUri = new(baseUri, parmUri.OriginalString);
103+
Console.WriteLine($"{finalUri.OriginalString} == {fullUri.OriginalString}");
104+
Assert.AreEqual(finalUri.OriginalString, correctFullUri);
105+
Assert.AreEqual(fullUri.OriginalString, correctFullUri);
106+
}
107+
93108
[TestMethod]
94109
[DataRow("", typeof(ArgumentNullException), "ExpectedArgumentNullException")]
95110
[DataRow("foo", typeof(ArgumentException), "Expected ArgumentException")]
@@ -467,3 +482,4 @@ private static void PrintUriPropertiesToConsole(Uri uri)
467482
}
468483
}
469484
}
485+

nanoFramework.System.Net.Http/Http/System.Uri.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,11 @@ public Uri(
556556
{
557557
throw new FormatException();
558558
}
559-
560-
ConstructAbsoluteUri(baseUri.AbsoluteUri + relativeUri);
559+
560+
// We need to have http://myuri/relative and sometimes the / is missing
561+
var baseadj = baseUri.AbsoluteUri.EndsWith("/") ? baseUri.AbsoluteUri : baseUri.AbsoluteUri + "/";
562+
var relativeadj = relativeUri.StartsWith("/") ? relativeUri.Substring(1) : relativeUri;
563+
ConstructAbsoluteUri(baseadj + relativeadj);
561564
}
562565

563566
/// <summary>

0 commit comments

Comments
 (0)