uhaciogullari / SimpleMvcSitemap

A minimalist library for creating sitemap files inside ASP.NET MVC and ASP.NET Core MVC applications
MIT License
128 stars 39 forks source link

SitemapNode with empty url creates invalid sitemap markup #27

Closed Xeevis closed 6 years ago

Xeevis commented 6 years ago

I'm dynamically adding nodes from my menu provider

foreach (var menuItem in menu.Items)
{
    nodes.AddRange(GetAllChildren(menuItem, c => c.Items).Select(x => new SitemapNode(x.Url)));
}

And it happened I added menu item placeholder without an url, this resulted in invalid sitemap because absence of url renders invalid tag.

I had to add extra check to make sure that doesn't happen from my code.

.Where(x => !string.IsNullOrWhiteSpace(x?.Url))

It might be a good idea to add check that prevents rendering of SitemapNode when url is empty to prevent invalid sitemap scenario.

uhaciogullari commented 6 years ago

I think throwing an exception is no better than creating some invalid nodes. I certainly won't put filtering code for this scenario into the library. I think it's better if you do this check in your own code.