From 7bbbe494d5a44b9ee06a5e53bbee76110718a68e Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Mon, 15 Apr 2024 11:56:52 -0700 Subject: [PATCH 1/4] Avoid throwing null exception Fix #15752 --- .../Views/NavigationItemLink-admin.cshtml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml b/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml index a7e8ae2bb81..0fdbba383a2 100644 --- a/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml +++ b/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml @@ -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)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"); From ab3a974876773561bcada44dfc8d160afd66ffb0 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Mon, 15 Apr 2024 12:01:24 -0700 Subject: [PATCH 2/4] update --- .../TheAdmin/Views/NavigationItemLink-admin.cshtml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml b/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml index 0fdbba383a2..c356d8690c8 100644 --- a/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml +++ b/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml @@ -7,15 +7,12 @@ TagBuilder tag = Tag(Model, "a"); tag.Attributes["id"] = null; + tag.Attributes["href"] = Model.Href; - if (Model.Href == null || 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-"; From 4e77698e8a419311e1dd78e8a8222c02c0ebbefd Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Mon, 15 Apr 2024 16:19:59 -0700 Subject: [PATCH 3/4] Update NavigationItemLink-admin.cshtml --- .../TheAdmin/Views/NavigationItemLink-admin.cshtml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml b/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml index c356d8690c8..1b7fd139892 100644 --- a/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml +++ b/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml @@ -7,11 +7,12 @@ TagBuilder tag = Tag(Model, "a"); tag.Attributes["id"] = null; - tag.Attributes["href"] = Model.Href; - if (Model.Href != null && 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-"; From c6d384c210a5a3ae398e7043056d3e922b1b54c5 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Mon, 15 Apr 2024 16:20:22 -0700 Subject: [PATCH 4/4] Update NavigationItemLink-admin.cshtml --- .../TheAdmin/Views/NavigationItemLink-admin.cshtml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml b/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml index 1b7fd139892..c93a83c959c 100644 --- a/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml +++ b/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml @@ -11,7 +11,9 @@ if (Model.Href == null || Model.Href.ToString() == "#") { tag.Attributes["href"] = "#m" + Model.GetHashCode().ToString(); - } else { + } + else + { tag.Attributes["href"] = Model.Href; }