Fix regex pattern for character conversion
Related Issue
#1404
New Behavior
Correct replacement of dashes and dots in slugs.
Contrast to Current Behavior
Incorrect replacement leads to errors when using slugs with multiple consecutive dashes.
Discussion: Benefits and Drawbacks
This would make it possible to use tags like customer--123 without errors.
There are also open source projects (e.g. Yaook) that frequently use multiple consecutive dashes in Netbox tags (yaook--default-gateway).
At this point, however, I would like to question why dashes are replaced in slugs at all, since dashes are valid characters in slugs.
Changes to the Documentation
not needed
Proposed Release Note Entry
Fixed regex pattern for character conversion when using slug parameter in multiple modules
Double Check
- [x] I have read the comments and followed the CONTRIBUTING.md.
- [x] I have explained my PR according to the information in the comments or in a linked issue.
- [x] My PR targets the
develbranch.
I'm digging into this a bit more, I used git blame to look up #101 which references #95, where they have a comment where they look at how the Netbox frontend javascript handles creating slugs.
The code has obviously changed since then, but doing a search I came across https://github.com/netbox-community/netbox/blob/f0507d00bfd077755619b420eae8a5d8dc979d94/netbox/project-static/src/buttons/reslug.ts#L10 which has the code, but also does not appear to trim the number of hyphens.
So, I think we should take the opportunity to make _to_slug reflect what NetBox does, which I believe can be done per the suggestion I put inline.