Skip to content

Commit

Permalink
Enforce valid hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Jul 26, 2021
1 parent 8d1baf8 commit e039edd
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tasmota/tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit e039edd

Please sign in to comment.