Fixes #8: Strip all not supported chars in manufacturer slug #42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a problem with stripping special characters from manufacturers names for the slug.
For example: "Rohde & Schwarz" would be stripped down to "rohde_&_schwarz" which is not a clean solution.
When manually creating a manufacturer in Netbox with that name, Netbox strips the slug down to "rohde-schwarz" which is much cleaner.
So I implemented a change which strips all special characters (and white spaces) and replaces them with a single hyphen (-). This solves the problem of special chars other than white spaces, and also when there are multiple behind each other.
Also changed the underscore to hyphen as the Netbox uses hyphens by default (avoiding problems with existing manufacturer entries).
A few examples:
Rohde & Schwarz --> rohde-schwarz
Palo Alto --> palo-alto
Example - Vendor --> example-vendor
Technical explanation: Used the regular expression module with
\W+
(equivalent to[^a-zA-Z0-9_]
) as this matches any non-word chars.Fixes #8