Better Fix config filename truncation

Better Fix config filename truncation (#2484)
This commit is contained in:
Theo Arends 2018-04-20 17:43:20 +02:00
parent a8b83aa036
commit c8277472b9
3 changed files with 5 additions and 5 deletions

View File

@ -44,8 +44,8 @@ The following devices are supported:
- [iTead Sonoff SV](https://www.itead.cc/smart-home/sonoff-sv.html)<img src="https://github.com/arendst/arendst.github.io/blob/master/media/sonoff_th.jpg" width="250" align="right" />
- [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)

View File

@ -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;
}

View File

@ -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));