Skip to content

Commit d349127

Browse files
Potential fix for code scanning alert no. 200: Nested 'if' statements can be combined
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 733cf90 commit d349127

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/BlazorWebFormsComponents/CustomControls/HtmlTextWriter.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ public void AddAttribute(string name, string value)
7171
throw new ArgumentNullException(nameof(name));
7272

7373
// Special handling for class attribute - concatenate instead of replace
74-
if (name.Equals("class", StringComparison.OrdinalIgnoreCase) && _pendingAttributes.TryGetValue("class", out var existingClass))
74+
if (name.Equals("class", StringComparison.OrdinalIgnoreCase)
75+
&& _pendingAttributes.TryGetValue("class", out var existingClass)
76+
&& !string.IsNullOrEmpty(existingClass)
77+
&& !string.IsNullOrEmpty(value))
7578
{
76-
if (!string.IsNullOrEmpty(existingClass) && !string.IsNullOrEmpty(value))
77-
{
78-
_pendingAttributes["class"] = $"{existingClass} {value}";
79-
return;
80-
}
79+
_pendingAttributes["class"] = $"{existingClass} {value}";
80+
return;
8181
}
8282

8383
_pendingAttributes[name] = value ?? string.Empty;

0 commit comments

Comments
 (0)