@@ -31,24 +31,26 @@ public DefaultStreamLoader(Uri baseUrl)
3131 /// <inheritdoc/>
3232 public async Task < Stream > LoadAsync ( Uri uri , CancellationToken cancellationToken = default )
3333 {
34- Uri absoluteUri ;
35- absoluteUri = baseUrl . AbsoluteUri . Equals ( OpenApiConstants . BaseRegistryUri ) ? new Uri ( Directory . GetCurrentDirectory ( ) + uri )
36- : new Uri ( baseUrl , uri ) ;
34+ var absoluteUri = ( baseUrl . AbsoluteUri . Equals ( OpenApiConstants . BaseRegistryUri ) , baseUrl . IsAbsoluteUri , uri . IsAbsoluteUri ) switch
35+ {
36+ ( true , _ , _ ) => new Uri ( Path . Combine ( Directory . GetCurrentDirectory ( ) , uri . ToString ( ) ) ) ,
37+ // this overcomes a URI concatenation issue for local paths on linux OSes
38+ ( _, true , false ) when baseUrl . Scheme . Equals ( "file" , StringComparison . OrdinalIgnoreCase ) =>
39+ new Uri ( Path . Combine ( baseUrl . AbsoluteUri , uri . ToString ( ) ) ) ,
40+ ( _, _, _) => new Uri ( baseUrl , uri ) ,
41+ } ;
3742
38- switch ( absoluteUri . Scheme )
43+ return absoluteUri . Scheme switch
3944 {
40- case "file" :
41- return File . OpenRead ( absoluteUri . AbsolutePath ) ;
42- case "http" :
43- case "https" :
45+ "file" => File . OpenRead ( absoluteUri . AbsolutePath ) ,
46+ "http" or "https" =>
4447#if NET5_0_OR_GREATER
45- return await _httpClient . GetStreamAsync ( absoluteUri , cancellationToken ) . ConfigureAwait ( false ) ;
48+ await _httpClient . GetStreamAsync ( absoluteUri , cancellationToken ) . ConfigureAwait ( false ) ,
4649#else
47- return await _httpClient . GetStreamAsync ( absoluteUri ) . ConfigureAwait ( false ) ;
50+ await _httpClient . GetStreamAsync ( absoluteUri ) . ConfigureAwait ( false ) ,
4851#endif
49- default :
50- throw new ArgumentException ( "Unsupported scheme" ) ;
51- }
52+ _ => throw new ArgumentException( "Unsupported scheme" ) ,
53+ } ;
5254 }
5355 }
5456}
0 commit comments