Skip to content

Commit fc1d93c

Browse files
committed
Fixes #268, no guard clause checking to ensure "name" or "HtmlHelper" dictionary keys exist before they are used.
1 parent fbf33af commit fc1d93c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/MvcSiteMapProvider/MvcSiteMapProvider/FilteredSiteMapNodeVisibilityProvider.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,28 @@ public override bool IsVisible(ISiteMapNode node, IDictionary<string, object> so
3636
}
3737
visibility = visibility.Trim();
3838

39-
// Check for the source HtmlHelper
40-
if (sourceMetadata["HtmlHelper"] == null)
39+
string name = string.Empty;
40+
string htmlHelper = string.Empty;
41+
if (sourceMetadata.ContainsKey("name"))
42+
{
43+
name = Convert.ToString(sourceMetadata["name"]);
44+
}
45+
if (sourceMetadata.ContainsKey("HtmlHelper"))
46+
{
47+
htmlHelper = Convert.ToString(sourceMetadata["HtmlHelper"]);
48+
}
49+
50+
// Check for the source HtmlHelper or given name. If neither are configured,
51+
// then always visible.
52+
if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(htmlHelper))
4153
{
4254
return true;
4355
}
44-
string name = Convert.ToString(sourceMetadata["name"]);
45-
string htmlHelper = Convert.ToString(sourceMetadata["HtmlHelper"]);
56+
57+
// Chop off the namespace
4658
htmlHelper = htmlHelper.Substring(htmlHelper.LastIndexOf(".") + 1);
4759

60+
// Get the keywords
4861
var visibilityKeywords = visibility.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
4962

5063
// All set. Now parse the visibility variable.

0 commit comments

Comments
 (0)