Skip to content

Commit

Permalink
Avoid null exception when href is null in admin menus (#15765)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Apr 22, 2024
1 parent 57bf155 commit 97fd760
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@

TagBuilder tag = Tag(Model, "a");
tag.Attributes["id"] = null;
tag.Attributes["href"] = Model.Href;

if (Model.Href.ToString() == "#")
if (Model.Href == null || Model.Href.ToString() == "#")
{
tag.Attributes["href"] = "#m" + Model.GetHashCode().ToString();
}
else
{
tag.Attributes["href"] = Model.Href;
}

var prefix = "icon-class-";

// Extract classes that are not icons from Model.Classes
// Extract classes that are not icons from Model.Classes.
var notIconClasses = ((IEnumerable<string>)Model.Classes)
.ToList()
.Where(c => !c.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));
.Where(c => !c.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
.ToArray();

if (notIconClasses.Count() > 0)
if (notIconClasses.Length > 0)
{
tag.Attributes["class"] = string.Join(" ", notIconClasses);
tag.Attributes["class"] = string.Join(' ', notIconClasses);
}

tag.AddCssClass("item-label d-flex");
Expand Down

0 comments on commit 97fd760

Please sign in to comment.