Skip to content

Commit

Permalink
Fixed issue where result was always empty if DeniedCharactersRegex wa…
Browse files Browse the repository at this point in the history
…s set.
  • Loading branch information
Lars Knemeyer authored and Lars Knemeyer committed Feb 1, 2021
1 parent d992a98 commit 8886aeb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Slugify.Core/SlugHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public string GenerateSlug(string inputString)
_deleteRegexMap.Add(Config.DeniedCharactersRegex, deniedCharactersRegex);
}

var currentValue = sb.ToString();
sb.Clear();
sb.Append(DeleteCharacters(sb.ToString(), deniedCharactersRegex));
sb.Append(DeleteCharacters(currentValue, deniedCharactersRegex));
}

if (Config.CollapseDashes)
Expand Down
15 changes: 15 additions & 0 deletions tests/Slugify.Core.Tests/SlugHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ public void TestDeniedCharacterDeletionLegacy()
Assert.Equal(expected, helper.GenerateSlug(original));
}


[Fact]
public void TestDeniedCharacterDeletionLegacyKeepsAllowedCharacters()
{
const string original = "Abc-123.$1$_x";
const string expected = "abc-123.1_x";

var helper = Create(new SlugHelperConfiguration
{
DeniedCharactersRegex = @"[^a-zA-Z0-9\-\._]"
});

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

[Fact]
public void TestCharacterReplacementWithWhitespace()
{
Expand Down

0 comments on commit 8886aeb

Please sign in to comment.