Skip to content

Commit

Permalink
Fixed settings page broken by using "%" in input fields (fixes #1516 )
Browse files Browse the repository at this point in the history
  • Loading branch information
Aircoookie committed Jun 30, 2021
1 parent 8b6cc70 commit 7483d3b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### Builds after release 0.12.0

#### Build 2106302

- Fixed settings page broken by using "%" in input fields

#### Build 2106301

- Fixed a problem with disabled buttons reverting to pin 0 causing conflict
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

// version code in format yymmddb (b = daily build)
#define VERSION 2106301
#define VERSION 2106302

//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG
Expand Down
17 changes: 14 additions & 3 deletions wled00/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,24 @@ void sappends(char stype, const char* key, char* val)
{
switch(stype)
{
case 's': //string (we can interpret val as char*)
case 's': { //string (we can interpret val as char*)
oappend("d.Sf.");
oappend(key);
oappend(".value=\"");
oappend(val);
//convert "%" to "%%" to make EspAsyncWebServer happy
char buf[130];
uint8_t len = strlen(val) +1;
uint8_t s = 0;
for (uint8_t i = 0; i < len; i++) {
buf[i+s] = val[i];
if (val[i] == '%') {
s++; buf[i+s] = '%';
}
}

oappend(buf);
oappend("\";");
break;
break; }
case 'm': //message
oappend(SET_F("d.getElementsByClassName"));
oappend(key);
Expand Down

1 comment on commit 7483d3b

@blazoncek
Copy link
Collaborator

@blazoncek blazoncek commented on 7483d3b Jun 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could simplify that by using String and .replace() not loosing too many cycles or too much RAM since it can be locally scoped.
Like so:

      String buf = val;
      buf.replace("%","%%");
      oappend("d.Sf.");
      oappend(key);
      oappend(".value=\"");
      oappend(buf.c_str());
      oappend("\";");

Please sign in to comment.