ansible_modules icon indicating copy to clipboard operation
ansible_modules copied to clipboard

Fix regex pattern for character conversion

Open mabezi opened this issue 3 weeks ago • 1 comments

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 devel branch.

mabezi avatar Dec 10 '25 12:12 mabezi

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.

sc68cal avatar Dec 10 '25 19:12 sc68cal