1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-10 15:22:24 +01:00

Ensure names containing characters other than a-z A-Z 0-9 or _ are unique (#5810)

This commit is contained in:
J. Nick Koston
2023-11-24 00:29:08 +01:00
committed by GitHub
parent 9f8a896e13
commit 5c31bec8c2
3 changed files with 14 additions and 8 deletions

View File

@@ -357,6 +357,9 @@ def snake_case(value):
return value.replace(" ", "_").lower()
_DISALLOWED_CHARS = re.compile(r"[^a-zA-Z0-9_]")
def sanitize(value):
"""Same behaviour as `helpers.cpp` method `str_sanitize`."""
return re.sub("[^-_0-9a-zA-Z]", r"", value)
return _DISALLOWED_CHARS.sub("_", value)