Enforce valid hostname

This commit is contained in:
Theo Arends 2021-07-26 15:10:47 +02:00
parent 8d1baf8982
commit e039edde33
1 changed files with 2 additions and 1 deletions

View File

@ -382,7 +382,8 @@ void setup(void) {
}
char *s = TasmotaGlobal.hostname;
while (*s) {
if (' ' == *s) { *s = '_'; }
if (!(isalnum(*s) || ('.' == *s))) { *s = '-'; } // Valid hostname chars are A..Z, a..z, 0..9, . and -
if ((s == TasmotaGlobal.hostname) && ('-' == *s)) { *s = 'x'; } // First char cannot be a dash so replace by an x
s++;
}
snprintf_P(TasmotaGlobal.mqtt_topic, sizeof(TasmotaGlobal.mqtt_topic), ResolveToken(TasmotaGlobal.mqtt_topic).c_str());