From c8277472b9596e7c491fb4c6e1ef526e80d68193 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Fri, 20 Apr 2018 17:43:20 +0200 Subject: [PATCH] Better Fix config filename truncation Better Fix config filename truncation (#2484) --- README.md | 4 ++-- sonoff/support.ino | 4 ++-- sonoff/webserver.ino | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fd0d98f73..f7c00a1dd 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,8 @@ The following devices are supported: - [iTead Sonoff SV](https://www.itead.cc/smart-home/sonoff-sv.html) - [iTead Sonoff TH10/TH16 with temperature sensor](https://www.itead.cc/smart-home/sonoff-th.html) - [iTead Sonoff Dual (R2)](https://www.itead.cc/smart-home/sonoff-dual.html) -- [iTead Sonoff Pow](https://www.itead.cc/smart-home/sonoff-pow.html) -- [iTead Sonoff Pow R2](https://www.itead.cc/sonoff-pow-r2.html) +- [iTead Sonoff Pow with Energy Monitoring](https://www.itead.cc/smart-home/sonoff-pow.html) +- [iTead Sonoff Pow R2 with Energy Monitoring](https://www.itead.cc/sonoff-pow-r2.html) - [iTead Sonoff 4CH](https://www.itead.cc/smart-home/sonoff-4ch.html) - [iTead Sonoff 4CH Pro](https://www.itead.cc/smart-home/sonoff-4ch-pro.html) - [iTead S20 Smart Socket](https://www.itead.cc/smart-socket.html) diff --git a/sonoff/support.ino b/sonoff/support.ino index 401b74e17..34d271644 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -232,7 +232,7 @@ char* UpperCase_P(char* dest, const char* source) return dest; } -char* SpaceToUnderscore(char* dest, const char* source) +char* NoAlNumToUnderscore(char* dest, const char* source) { char* write = dest; const char* read = source; @@ -240,7 +240,7 @@ char* SpaceToUnderscore(char* dest, const char* source) while (ch != '\0') { ch = *read++; - *write++ = (ch == ' ') ? '_' : ch; + *write++ = (isalnum(ch) || ('\0' == ch)) ? ch : '_'; } return dest; } diff --git a/sonoff/webserver.ino b/sonoff/webserver.ino index 33cadbd16..1dc3eda52 100644 --- a/sonoff/webserver.ino +++ b/sonoff/webserver.ino @@ -962,7 +962,7 @@ void HandleBackupConfiguration() char attachment[100]; char friendlyname[sizeof(Settings.friendlyname[0])]; - snprintf_P(attachment, sizeof(attachment), PSTR("attachment; filename=Config_%s_%s.dmp"), SpaceToUnderscore(friendlyname, Settings.friendlyname[0]), my_version); + snprintf_P(attachment, sizeof(attachment), PSTR("attachment; filename=Config_%s_%s.dmp"), NoAlNumToUnderscore(friendlyname, Settings.friendlyname[0]), my_version); WebServer->sendHeader(F("Content-Disposition"), attachment); WebServer->send(200, FPSTR(HDR_CTYPE_STREAM), ""); memcpy(buffer, &Settings, sizeof(buffer));