ctolkien / Slugify

Simple Slug / Clean URL generator helper for Microsoft .NET framework / .NET Standard.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DeniedCharactersRegex broken in current NuGet build

poke opened this issue · comments

(tl;dr: You need to release fixes to NuGet)

So, this was a “fun” one. When attempting to use the library from NuGet, DeniedCharactersRegex doesn’t work and the library will always return an empty string, regardless of what you pass as input string.

To reproduce

Simple example, create a new console application and add the dependency:

dotnet new console
dotnet add package Slugify.Core

Edit the Program.cs to contain the following:

using Slugify;

var config = new SlugHelperConfiguration();
config.DeniedCharactersRegex = "[^abc]";

var helper = new SlugHelper(config);
Console.WriteLine($"'{helper.GenerateSlug("abcdef")}'");

Run the project:

PS > dotnet run
''

Analysis

As it turns out, the following code is the problem:

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

In the released NuGet version, this appears to be compiled to the following:

sb.Clear();
sb.Append(DeleteCharacters(sb.ToString(), deniedCharactersRegex));

Originally, I thought this was some compiler optimization bug where it would inline the ToString() call here. But looking further, I realized that the released NuGet version is actually a bit older and this is actually the real code there:

sb.Clear();
sb.Append(DeleteCharacters(sb.ToString(), deniedCharactersRegex));

Sooo, this was fixed in #22, and apparently that change never made it onto NuGet (along with some of the other fixes that happened last year). So can you publish a new version to NuGet soon? 😁

Related:
#27

So you don’t want to do a NuGet release manually and keep all these bugs in until you can automate the process? 😅

Hey @poke - finally got around to this... didn't actually mean for it to run... but here we are.. v4 just went out!

Spoke to soon, sent this to the local github nuget package repo.. not nuget for real

Fixed for reals now.!!!