ctolkien / Slugify

Simple Slug / Clean URL generator helper for Microsoft .NET framework / .NET Standard.
MIT License
97 stars 13 forks source link

StringReplacements for umlauts not working in 3.0.0 #25

Closed larskn closed 3 years ago

larskn commented 3 years ago

When I specify replacements for umlauts (e.g. "ae" for "ä" which is the common replacement) these are not working anymore after moving to 3.0.0

For this test:

[Fact]
public void TestUmlauts()
{
    const string original = "äöüÄÖÜß";
    const string expected = "aeoeueaeoeuess";

    var helper = new SlugHelper(new SlugHelperConfiguration
    {
        StringReplacements = new Dictionary<string, string>
        {
            {" ", "-" },
            {"Ä", "Ae" },
            {"Ö", "Oe" },
            {"Ü", "Ue" },
            {"ä", "ae" },
            {"ö", "oe" },
            {"ü", "ue" },
            {"ß", "ss" }
        },
    });

    Assert.Equal(expected, helper.GenerateSlug(original));
}

This is the result: image

The reason is that the string normalisation changes the single umlaut char to multiple chars and therefore the replacement char is not found in the input string. image