Add EnableHashedShortening option for unique slug truncation#165
Add EnableHashedShortening option for unique slug truncation#165
Conversation
Co-authored-by: ctolkien <515955+ctolkien@users.noreply.github.com>
|
@copilot can you add some more tests combining the new hashing option, with other options to ensure the output remains correct. |
…ptions Co-authored-by: ctolkien <515955+ctolkien@users.noreply.github.com>
I've added 12 comprehensive tests that combine EnableHashedShortening with other configuration options to ensure correct behavior: ✅ ForceLowerCase combinations (case preservation with hashing) All 98 tests pass, confirming the hashing feature works correctly with all existing options. Commit: 5695a2b |
|
@copilot what hashing mechanism does dotnet use for a string object when you call GetHashCode()? Should we be worried about collisions and /or should we use a different hash such as Murmur? |
.NET's Current Implementation Issues:
Collision Risk Analysis: Recommendation: Use a more robust approach I suggest we implement a deterministic hash using a simple but effective algorithm like FNV-1a or a custom implementation that:
Would you like me to implement an improved hashing mechanism that addresses these concerns while maintaining backward compatibility? |
…lision resistance Co-authored-by: ctolkien <515955+ctolkien@users.noreply.github.com>
Summary
Adds a new
EnableHashedShorteningconfiguration option that prevents slug collisions when truncating long slugs to a maximum length. Instead of simple truncation, it appends a hash-based postfix to ensure uniqueness.Problem
The existing
MaximumLengthfeature only performs simple truncation, which can cause different inputs to produce identical slugs:Solution
The new
EnableHashedShorteningoption generates unique hash postfixes:Implementation Details
EnableHashedShortening = false)-54,-a2)MaximumLengthis too small for hash postfix, falls back to simple truncationGetHashCode()to avoid external dependenciesChanges
EnableHashedShorteningproperty toSlugHelperConfigurationSlugHelper.GenerateSlug()GenerateSlugHash()private method for hash generationTesting
All existing tests continue to pass, plus new tests verify:
Fixes #158.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.