This repository was archived by the owner on Jun 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed
Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,22 @@ namespace GitHub.Extensions
55{
66 public static class UriExtensions
77 {
8+ /// <summary>
9+ /// Appends a relative path to the URL.
10+ /// </summary>
11+ /// <remarks>
12+ /// The Uri constructor for combining relative URLs have a different behavior with URLs that end with /
13+ /// than those that don't.
14+ /// </remarks>
15+ public static Uri Append ( this Uri uri , string relativePath )
16+ {
17+ if ( ! uri . AbsolutePath . EndsWith ( "/" , StringComparison . Ordinal ) )
18+ {
19+ uri = new Uri ( uri + "/" ) ;
20+ }
21+ return new Uri ( uri , new Uri ( relativePath , UriKind . Relative ) ) ;
22+ }
23+
824 public static bool IsHypertextTransferProtocol ( this Uri uri )
925 {
1026 return uri . Scheme == "http" || uri . Scheme == "https" ;
Original file line number Diff line number Diff line change 1+ using System ;
2+ using GitHub . Extensions ;
3+ using Xunit ;
4+
5+ public class UriExtensionTests
6+ {
7+ public class TheAppendMethod
8+ {
9+ [ Theory ]
10+ [ InlineData ( "https://github.com/foo/bar" , "graphs" , "https://github.com/foo/bar/graphs" ) ]
11+ [ InlineData ( "https://github.com/foo/bar/" , "graphs" , "https://github.com/foo/bar/graphs" ) ]
12+ [ InlineData ( "https://github.com" , "bippety/boppety" , "https://github.com/bippety/boppety" ) ]
13+ [ InlineData ( "https://github.com/" , "bippety/boppety" , "https://github.com/bippety/boppety" ) ]
14+ [ InlineData ( "https://github.com/foo/bar" , "bippety/boppety" , "https://github.com/foo/bar/bippety/boppety" ) ]
15+ public void AppendsRelativePath ( string url , string relativePath , string expected )
16+ {
17+ var uri = new Uri ( url , UriKind . Absolute ) ;
18+ var expectedUri = new Uri ( expected , UriKind . Absolute ) ;
19+
20+ var result = uri . Append ( relativePath ) ;
21+
22+ Assert . Equal ( expectedUri , result ) ;
23+ }
24+ }
25+ }
Original file line number Diff line number Diff line change 141141 <Compile Include =" GitHub.App\ViewModels\RepositoryCreationViewModelTests.cs" />
142142 <Compile Include =" GitHub.App\ViewModels\RepositoryPublishViewModelTests.cs" />
143143 <Compile Include =" GitHub.Exports\VSServicesTests.cs" />
144+ <Compile Include =" GitHub.Extensions\UriExtensionTests.cs" />
144145 <Compile Include =" GitHub.Extensions\URITests.cs" />
145146 <Compile Include =" GitHub.Primitives\UriStringTests.cs" />
146147 <Compile Include =" GitHub.UI\TwoFactorInputTests.cs" />
You can’t perform that action at this time.
0 commit comments