Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/1499-fix-regex-pattern.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Fixed regex pattern for character conversion when using slug parameter in multiple modules
2 changes: 1 addition & 1 deletion plugins/module_utils/netbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ def _to_slug(self, value):
return value
else:
removed_chars = re.sub(r"[^\-\.\w\s]", "", value)
convert_chars = re.sub(r"[\-\.\s]+", "-", removed_chars)
convert_chars = re.sub(r"[\-\.\s]", "-", removed_chars)
Comment on lines 1428 to +1429
Copy link
Contributor

@sc68cal sc68cal Dec 10, 2025

Choose a reason for hiding this comment

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

At this point, however, I would like to question why dashes are replaced in slugs at all, since dashes are valid characters in slugs.

So, it may be that the issue of Ansible disallowing hyphens for group names, may have accidentally been applied to slugs as well. I agree, the documentation for slug fields explicitly permits hyphens.

So really, I have to wonder what exactly this was trying to prevent? Was it meant to just protect people from adding too many hyphens? I wonder if we shouldn't just remove this part completely?

Should it just be

        return re.sub(r"[^\-\.\w\s]", "", value)

?

Copy link
Author

Choose a reason for hiding this comment

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

Are you sure that this would cover all valid cases?

I hadn't thought about it before, but the regex allows periods, which should actually be prohibited.
It also doesn't accept underscores, which are definitely allowed.

A slug is a short label for something, containing only letters, numbers, underscores or hyphens.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't sure, so I went and looked. I think we need to update this function to be more aligned with what NetBox does in their code, see my comment

return convert_chars.strip().lower()

def _normalize_data(self, data):
Expand Down
Loading