-
-
Notifications
You must be signed in to change notification settings - Fork 14
Add EnableHashedShortening option for unique slug truncation #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: ctolkien <[email protected]>
@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 <[email protected]>
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 <[email protected]>
Summary
Adds a new
EnableHashedShortening
configuration 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
MaximumLength
feature only performs simple truncation, which can cause different inputs to produce identical slugs:Solution
The new
EnableHashedShortening
option generates unique hash postfixes:Implementation Details
EnableHashedShortening = false
)-54
,-a2
)MaximumLength
is too small for hash postfix, falls back to simple truncationGetHashCode()
to avoid external dependenciesChanges
EnableHashedShortening
property toSlugHelperConfiguration
SlugHelper.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.