-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template confused by data containing percent ('%') #333
Comments
This seems to be different from #300 where the percent in a CSS string is being mistaken for a placeholder, but the workaround for that, I'll try to take a look at the code and see if I can see a fix when time allows. For now, I would recommend the back tick as a less likely to be an issue option. In /src/WebResponseImpl.h
|
Hey, this sounds like an easy fix where you dont need to have any deep knowledge of the libraries. Remember you can do a pull request and contribute yourself with fixes :) |
Take a look at the code: In general I'm sure the issue is that it's not skipping past the inserted data before looking for another % but where it's going wrong on that is unclear. There are 4 or 5 different places where If I could watch it in a debugger, I could figure it out, but I'm not aware of a way to debug the ESP. |
LOL you are absolutely right :D My apologies :D |
Yeah, super :-) |
Platformio IDE with Visual Studio Code now has the debugger, it works for ESP too. But, unfortunately, it is a paid feature. PS My apologies to all of you, since I'm the author of that code. I don't like it either, but at that moment I thought that using memmove/memcpy/memchr would result in better performance than searching the string for templates byte-by-byte. Premature optimization is the root of all evil, as Donald Knuth said. Again, my apologies. |
Try the PR #366. You will need to pass the argument to the compiler to #define |
-DEBUG levels: 1 for serial only, 2 for serial and display. -User config device baudrate, poweron initialization string, data extraction and display: -- New /device.html page to configure all connected device options -- Send config.pwronstr to device pwrondelay seconds after startup -- Extract up to 3 data items returned from device for local display via scanf code: http://www.cplusplus.com/reference/cstdio/scanf/ -- Extracted values multiplied by slope plus offset and shown with name on the display -global.h config load/save simplified with EEPROM.get / EEPROM.put. -CONFIG_VER version number added. This update will clear prior config data to default! -txbuf to hold data waiting to be sent to the device so we can send this in a debug message -Support "hidden" /update page to upload web/js/css/etc files into SPIFFS for web server. This allows customization and rebranding for your solution without the need for Arduino code development. Put your own html/javascript in the device for user interface. -Default web page is index.htm from SPIFFS. /root is handle_root from Page_Root.h i.e. http://ip/ will display nothing until index.htm is uploaded via http://ip/update. If you want to use the built in homepage, go to http://ip/root TODO: serve root automatically if no index.htm in SPIFFS -Built in /root page converted from jquery to raw javascript for increased reliability and smaller size. This is critical when working in poor RF environments while directly connected to the device. -Use template processor in ESPAsyncWebServer for config pages. There are problems with this, see: -- me-no-dev/ESPAsyncWebServer#333 Must change TEMPLATE_PLACEHOLDER to '`' in \libraries\ESPAsyncWebServer\src\WebResponseImpl.h and trigger library re-compile -- me-no-dev/ESPAsyncWebServer#374 Must use "AI-THINKER" ESP-12E units -- Network setup /config.html NOT updated to templates for this reason. -Moving to a single general tag processor function "send_tag_values" -Moving to standard linking to .css and .js resources from config pages instead of the javascript window.onload functions. -Add debugq macro to append to debugbuf for later output. This avoids delays when debugging web responses -Increase max string length of ReadStringFromEEPROM from 60 to 65 -urldecode, avoids Strings, returns char*, expects length. -urlencode, expects char* vs String (still returns String). Simplified via nibble2hex. -HTMLencode added inorder to support all strings for scanf codes. -Optional support for NeoPixel LEDs. NOT enabled by default. -Start on a command processor language from server response or user input BUGFIX: IO pin 10 is NOT usable as SERIAL_ENABLE_PIN, back to IO5 D1 parseServer p1,p2 had not been initialized. Data returned from server for device could be lost.
-DEBUG levels: 1 for serial only, 2 for serial and display. -User config device baudrate, poweron initialization string, data extraction and display: -- New /device.html page to configure all connected device options -- Send config.pwronstr to device pwrondelay seconds after startup -- Extract up to 3 data items returned from device for local display via scanf code: http://www.cplusplus.com/reference/cstdio/scanf/ -- Extracted values multiplied by slope plus offset and shown with name on the display -global.h config load/save simplified with EEPROM.get / EEPROM.put. -CONFIG_VER version number added. This update will clear prior config data to default! -txbuf to hold data waiting to be sent to the device so we can send this in a debug message -Support "hidden" /update page to upload web/js/css/etc files into SPIFFS for web server. This allows customization and rebranding for your solution without the need for Arduino code development. Put your own html/javascript in the device for user interface. -Default web page is index.htm from SPIFFS. /root is handle_root from Page_Root.h i.e. http://ip/ will display nothing until index.htm is uploaded via http://ip/update. If you want to use the built in homepage, go to http://ip/root TODO: serve root automatically if no index.htm in SPIFFS -Built in /root page converted from jquery to raw javascript for increased reliability and smaller size. This is critical when working in poor RF environments while directly connected to the device. -Use template processor in ESPAsyncWebServer for config pages. There are problems with this, see: -- me-no-dev/ESPAsyncWebServer#333 Must change TEMPLATE_PLACEHOLDER to '`' in \libraries\ESPAsyncWebServer\src\WebResponseImpl.h and trigger library re-compile -- me-no-dev/ESPAsyncWebServer#374 Must use "AI-THINKER" ESP-12E units -- Network setup /config.html NOT updated to templates for this reason. -Moving to a single general tag processor function "send_tag_values" -Moving to standard linking to .css and .js resources from config pages instead of the javascript window.onload functions. -Add debugq macro to append to debugbuf for later output. This avoids delays when debugging web responses -Increase max string length of ReadStringFromEEPROM from 60 to 65 -urldecode, avoids Strings, returns char*, expects length. -urlencode, expects char* vs String (still returns String). Simplified via nibble2hex. -HTMLencode added inorder to support all strings for scanf codes. -Optional support for NeoPixel LEDs. NOT enabled by default. -Start on a command processor language from server response or user input BUGFIX: IO pin 10 is NOT usable as SERIAL_ENABLE_PIN, back to IO5 D1 parseServer p1,p2 had not been initialized. Data returned from server for device could be lost. Merge branch 'master' of https://github.com/JamesNewton/esp8266WebSerial # Conflicts: # esp8266WebSerial.ino # global.h
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
This is an unresolved and important issue. Sadly, it doesn't look like I'm allowed to re-open it? I guess I have to copy the text and open a new issue? |
@JamesNewton you can reopen it if needed. But it needs to be kept active. |
Again I do not appear to have permissions to reopen it. There is no reopen button available to me. |
Huh, that is very odd. @me-no-dev any ideas? |
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future. |
Thanks for re-opening. Just to be clear, there is a workaround for this issue since the TEMPLATE_PLACEHOLDER is now a supported define. The issue is that you must pick one character to lose which you can never have in data placed in that field. Rather than parsing the template character out and replacing it with data and then moving forward from /after/ the inserted data, it is re-scanning the inserted data and finding template markers in it. I thought the fix would be easy, but having looked at the current code, I'll admit that I'm seriously confused by it and can't see how to apply that seemly simple idea. Hopefully someone smarter than I can do it. |
I think i had the xame issue a while ago, that my StringProcessor replaced content between two "%" symbols e.g. in my css. You simply have to escape the Placeholder with another "%".
|
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
I can confirm that doubling the '%' character has the desired effect. |
Doubling the %% creates invalid CSS so not a workable / usable solution. Any solution that creates another issue is not a solution at all. ;) |
Edit: I am sure that what I wrote below worked briefly, but I had to edit the value in the library after all. The line is in WebResponseImpl.h at line 63 in the latest version. Easy to do, but not as easy to explain to the dozens of students who may need to download and use this in the future. I also changed from using "`" to "@". That may be a more common character, but in my case there was no conflict and the backtick is used in some javascript variable replacement code. Just a note for users like me who have just run into this. As of 1.2.7 (and probably earlier) you can simply define what one character to use before including the header file. It will use what you provide. As others have said, you sacrifice that one character, #define TEMPLATE_PLACEHOLDER '`' Thanks to those who provided this information above. I have simply tried to make it obvious how to use it. |
Setup: Web page for user configuration of device settings located in PROGMEM with placeholders. User function replacing placeholders with configuration data. The configuration data is a char array and one of the characters is a %.
Observed behavior: When requested via HTTP 1.0 everything is as expected. Via HTTP 1.1, all of the web page from the % in the data, to the % in the last placeholder is replaced with the names of the remaining placeholders. No idea why the 1.0 vs the 1.1 would make a difference. Is 1.0 not chunked?
Code to reproduce: (I hope you don't mind an excerpt here, I think it gets the idea across very well). In setup:
and in the included Pages.h file:
The problem is when the config.dataregexp1 is set to a value containing a '%' character. In this case, it is set to
r_0000_%3x
.Using a little utility called web bug that allows me to control the http data request and see the raw returned values, I am testing this and when using HTTP 1.0, I get this:
But when using HTTP/1.1, as Chrome and other browsers will do, I get:
The text was updated successfully, but these errors were encountered: