Skip to content
Merged
Changes from 2 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
20 changes: 15 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 @@ private static ReadResult InternalLoad(MemoryStream input, string format, OpenAp
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,11 +320,21 @@ private static ReadResult InternalLoad(MemoryStream input, string format, OpenAp
}
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 (
Expand Down