@@ -31,24 +31,26 @@ public DefaultStreamLoader(Uri baseUrl)
31
31
/// <inheritdoc/>
32
32
public async Task < Stream > LoadAsync ( Uri uri , CancellationToken cancellationToken = default )
33
33
{
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
+ } ;
37
42
38
- switch ( absoluteUri . Scheme )
43
+ return absoluteUri . Scheme switch
39
44
{
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" =>
44
47
#if NET5_0_OR_GREATER
45
- return await _httpClient . GetStreamAsync ( absoluteUri , cancellationToken ) . ConfigureAwait ( false ) ;
48
+ await _httpClient . GetStreamAsync ( absoluteUri , cancellationToken ) . ConfigureAwait ( false ) ,
46
49
#else
47
- return await _httpClient . GetStreamAsync ( absoluteUri ) . ConfigureAwait ( false ) ;
50
+ await _httpClient . GetStreamAsync ( absoluteUri ) . ConfigureAwait ( false ) ,
48
51
#endif
49
- default :
50
- throw new ArgumentException ( "Unsupported scheme" ) ;
51
- }
52
+ _ => throw new ArgumentException( "Unsupported scheme" ) ,
53
+ } ;
52
54
}
53
55
}
54
56
}
0 commit comments