Skip to content

Commit

Permalink
Merge pull request #22 from larskn/bugfix/denied-characters-regex-alw…
Browse files Browse the repository at this point in the history
…ays-empty-result

Fixed issue where result was always empty if DeniedCharactersRegex was set.
  • Loading branch information
ctolkien authored Nov 1, 2021
2 parents 113adfc + 8886aeb commit 9c1e3dc
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 9c1e3dc

Please sign in to comment.