Skip to content

Commit 628d341

Browse files
Fix invalid condition
1 parent 229d925 commit 628d341

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/ImageSharp.Web/FormatUtilities.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,23 @@ public bool TryGetExtensionFromUri(string uri, [NotNullWhen(true)] out string? e
8888
path = uri;
8989
}
9090

91-
// We don't need this if the query string has already provided a valid extension.
92-
if (extension == null)
91+
int extensionIndex;
92+
if ((extensionIndex = path.LastIndexOf('.')) != -1)
9393
{
94-
int extensionIndex;
95-
if ((extensionIndex = path.LastIndexOf('.')) != -1)
96-
{
97-
ReadOnlySpan<char> pathExtension = path[(extensionIndex + 1)..];
94+
ReadOnlySpan<char> pathExtension = path[(extensionIndex + 1)..];
9895

99-
foreach (string e in this.extensions)
96+
foreach (string e in this.extensions)
97+
{
98+
if (pathExtension.Equals(e, StringComparison.OrdinalIgnoreCase))
10099
{
101-
if (pathExtension.Equals(e, StringComparison.OrdinalIgnoreCase))
102-
{
103-
extension = e;
104-
return true;
105-
}
100+
// We've found a valid extension in the path, however we do not
101+
// want to overwrite an existing extension.
102+
extension ??= e;
103+
return true;
106104
}
107-
108-
return false;
109105
}
106+
107+
return false;
110108
}
111109

112110
return extension != null;

0 commit comments

Comments
 (0)