Skip to content
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

Improve Name-to-Slug parsing to better align with Netbox UI #809

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion plugins/module_utils/netbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,8 +1162,10 @@ def _to_slug(self, value):
return value
else:
removed_chars = re.sub(r"[^\-\.\w\s]", "", value)
removed_chars = removed_chars.encode('ascii', errors="ignore").decode()
removed_chars = removed_chars.strip()
convert_chars = re.sub(r"[\-\.\s]+", "-", removed_chars)
return convert_chars.strip().lower()
return convert_chars.lower()

def _normalize_data(self, data):
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/module_utils/test_data/normalize_data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
},
{
"before": {
"slug": "Test to_slug"
"slug": "Test to_slug© ⅛ äüöß 👀"
},
"after": {
"slug": "test-to_slug"
Expand Down Expand Up @@ -345,4 +345,4 @@
"mac_address": "AA:BB:CC:DD:EE:FF"
}
}
]
]