netbox-community / Device-Type-Library-Import

This library is intended to assist with importing device and module types into NetBox from the NetBox Community DeviceType-Library
https://github.com/netbox-community/devicetype-library
MIT License
265 stars 82 forks source link

Fixes #8: Strip all not supported chars in manufacturer slug #42

Closed FloEisen closed 2 years ago

FloEisen commented 2 years ago

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