Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddTrailingSlash throwing exception #104

Open
Vidofner opened this issue Mar 4, 2024 · 0 comments
Open

AddTrailingSlash throwing exception #104

Vidofner opened this issue Mar 4, 2024 · 0 comments

Comments

@Vidofner
Copy link

Vidofner commented Mar 4, 2024

If an admin has filled out "path to avoid" in this way (with a trailing semicolon) in the config then the property PathsToAvoid in the SiteMapData object will contain an empty string
Skärmbild 2024-03-04 104517

When generating the sitemap this method will throw an exception since it's trying to check on a negative index of this string that is empty

        private static string AddTailingSlash(string url)
        {
            if (url[url.Length - 1] != '/')
            {
                url = url + "/";
            }

            return url;
        }

The config tool should avoid saving empty strings and the AddTrailingSlash method should be changed to this

        private static string AddTailingSlash(string url)
        {
            if (!string.IsNullOrWhiteSpace(url) && url[^1] != '/')
            {
                url += "/";
            }

            return url;
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants