Skip to content

Feature/slug generator, first 3 tasks - #6

Open
MostafaShraief wants to merge 8 commits into
mainfrom
feature/slug-generator
Open

Feature/slug generator, first 3 tasks#6
MostafaShraief wants to merge 8 commits into
mainfrom
feature/slug-generator

Conversation

@MostafaShraief

Copy link
Copy Markdown
Collaborator
  • Extend to custom separator slug generation.
  • Implement a C# Extension Method for slug generation.
  • Ensure collision prevention for identical titles.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the slug generator library to support custom separators, adds a string extension method for hyphen-based slugs, and introduces a “unique slug” generator intended to reduce collisions for identical titles.

Changes:

  • Added CustomGenerate(text, separator) plus GenerateHyphens/GenerateUnderscores convenience methods.
  • Added StringExtensions.ToSlug() for hyphen-separated slugs.
  • Added GenerateUnique(text) and updated/expanded unit tests to cover the new APIs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
SlugGeneratorLibrary/SlugGenerator.cs Adds custom-separator generation, convenience methods, a “unique” slug generator, and a ToSlug() extension method.
SlugGeneratorUnitTesting/SlugAlgorithmUnitTest.cs Updates existing tests to use GenerateHyphens and adds coverage for ToSlug, custom separators, underscores, and uniqueness.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread SlugGeneratorLibrary/SlugGenerator.cs
Comment thread SlugGeneratorUnitTesting/SlugAlgorithmUnitTest.cs Outdated
Comment thread SlugGeneratorUnitTesting/SlugAlgorithmUnitTest.cs Outdated
Comment thread SlugGeneratorUnitTesting/SlugAlgorithmUnitTest.cs Outdated
Comment thread SlugGeneratorLibrary/SlugGenerator.cs Outdated
Comment on lines +15 to +16
text = Regex.Replace(text, @"[+()^*%#@!/\\.,|`~]+", string.Empty);
text = Regex.Replace(text, @"[\s_-]+", "-");
text = Regex.Replace(text, @"[\s_-]+", separator.ToString());

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introducing CustomGenerate changes behavior for custom separators that are currently treated as removable characters (e.g., . and * are stripped by the first regex). With separator='.', an input like "hello.world" would lose the dot instead of treating it as a separator. Consider excluding the chosen separator from the removal regex and/or treating it as a valid separator in the normalization regex.

Copilot uses AI. Check for mistakes.
Comment thread SlugGeneratorLibrary/SlugGenerator.cs
Comment thread SlugGeneratorLibrary/SlugGenerator.cs Outdated
Comment thread SlugGeneratorLibrary/SlugGenerator.cs Outdated
public static string Generate(string text)
public static string CustomGenerate(string text, char separator)
{
if (text is null)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead you can use ArgumentNullException.ThrowIfNull(text); which is the modern standard way

Comment thread SlugGeneratorLibrary/SlugGenerator.cs Outdated
throw new ArgumentNullException(nameof(text));
// append text with a GUID-based suffix to greatly reduce collision risk
string uniqueText = text + '-' + Guid.NewGuid().ToString("N");
return GenerateHyphens(uniqueText);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slugify the base text first, and then append the GUID to the already-cleaned string.

Assert.Equal("hello", SlugGenerator.GenerateHyphens("Hello*"));
Assert.Equal("hello", SlugGenerator.GenerateHyphens("Hello()"));
Assert.Equal("helloworld", SlugGenerator.GenerateHyphens("Hello()!@#%^*+/\\.|`~,world"));
Assert.Equal("hello-world", SlugGenerator.GenerateHyphens("Hello_- ()!@#%^*+/\\.|`~,- world"));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try this tc:
!@# Hello World

{
ArgumentNullException.ThrowIfNull(text);
// append text with a GUID-based suffix to greatly reduce collision risk
string uniqueText = text;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is unnecessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants