Skip to content

Commit b04d2cd

Browse files
BugFix: Update to _to_slug (#101)
1 parent fae70e0 commit b04d2cd

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

plugins/module_utils/netbox_utils.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# Import necessary packages
99
import traceback
10+
import re
1011
from itertools import chain
1112
from ansible.module_utils.compat import ipaddress
1213
from ansible.module_utils._text import to_text
@@ -580,11 +581,10 @@ def _to_slug(self, value):
580581
return value
581582
elif isinstance(value, int):
582583
return value
583-
elif " " in value:
584-
slug = value.replace(" ", "-").lower()
585584
else:
586-
slug = value.lower()
587-
return slug
585+
removed_chars = re.sub(r"[^\-\.\w\s]", "", value)
586+
convert_chars = re.sub(r"[\-\.\s]+", "-", removed_chars)
587+
return convert_chars.strip().lower()
588588

589589
def _normalize_data(self, data):
590590
"""

tests/unit/module_utils/test_data/build_query_params_child/data.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,4 @@
177177
"tenant_id": 1
178178
}
179179
}
180-
]
180+
]

tests/unit/module_utils/test_data/build_query_params_no_child/data.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,4 @@
316316
"cluster_id": 1
317317
}
318318
}
319-
]
319+
]

tests/unit/module_utils/test_data/slug/data.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@
1818
{
1919
"non_slug": null,
2020
"expected": null
21+
},
22+
{
23+
"non_slug": "test1.example.com",
24+
"expected": "test1-example-com"
2125
}
22-
]
26+
]

0 commit comments

Comments
 (0)