Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@
Stream stream;
string? format;

if (url.StartsWith("http", StringComparison.OrdinalIgnoreCase)
|| url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
if (url.StartsWith("http:", StringComparison.OrdinalIgnoreCase)
|| url.StartsWith("https:", StringComparison.OrdinalIgnoreCase))
{
var response = await settings.HttpClient.GetAsync(url, token).ConfigureAwait(false);
var mediaType = response.Content.Headers.ContentType?.MediaType;
Expand All @@ -320,15 +320,27 @@
}
else
{
format = Path.GetExtension(url).Split('.').LastOrDefault();

try
{
var fileInput = new FileInfo(url);
string fileName;
if (url.StartsWith("file:", StringComparison.OrdinalIgnoreCase))
{
fileName = new Uri(url).LocalPath;
}
else
{
fileName = url;
}
Comment on lines +326 to +333

Check notice

Code scanning / CodeQL

Missed ternary opportunity Note

Both branches of this 'if' statement write to the same variable - consider using '?' to express intent better.

format = Path.GetExtension(fileName).Split('.').LastOrDefault();

var fileInput = new FileInfo(fileName);
stream = fileInput.OpenRead();
}
catch (Exception ex) when (
ex is
UriFormatException or
FormatException or
FileNotFoundException or
PathTooLongException or
DirectoryNotFoundException or
Expand Down
Loading