diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e23a3fc4..fc28c5524 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### Added - Matter support for Light and Relays on ESP32 by Stephan Hadinger (#18320) - ESP32 WIP support for 16 shutters using `#define USE_SHUTTER_ESP32` in addition to `USE_SHUTTER` by Stefan Bode (#18295) +- Berry `webserver.html_escape()` reusing the internal HTML escaping function ### Breaking Changed diff --git a/lib/libesp32/berry_tasmota/src/be_webserver_lib.c b/lib/libesp32/berry_tasmota/src/be_webserver_lib.c index ad7bcadd7..0cdf4ede0 100644 --- a/lib/libesp32/berry_tasmota/src/be_webserver_lib.c +++ b/lib/libesp32/berry_tasmota/src/be_webserver_lib.c @@ -24,6 +24,8 @@ extern int w_webserver_content_flush(bvm *vm); extern int w_webserver_content_stop(bvm *vm); extern int w_webserver_content_button(bvm *vm); +extern int w_webserver_html_escape(bvm *vm); + extern int w_webserver_argsize(bvm *vm); extern int w_webserver_arg(bvm *vm); extern int w_webserver_arg_name(bvm *vm); @@ -48,6 +50,8 @@ module webserver (scope: global) { content_stop, func(w_webserver_content_stop) content_button, func(w_webserver_content_button) + html_escape, func(w_webserver_html_escape) + arg_size, func(w_webserver_argsize) arg, func(w_webserver_arg) arg_name, func(w_webserver_arg_name) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_webserver.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_webserver.ino index 599548ac4..f37be12b5 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_webserver.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_webserver.ino @@ -247,6 +247,20 @@ extern "C" { be_raise(vm, kTypeError, nullptr); } + // Berry: `webserver.html_escape(string) -> string` + // + int32_t w_webserver_html_escape(struct bvm *vm); + int32_t w_webserver_html_escape(struct bvm *vm) { + int32_t argc = be_top(vm); // Get the number of arguments + if (argc >= 1 && be_isstring(vm, 1)) { + const char * text = be_tostring(vm, 1); + String html = HtmlEscape(text); + be_pushstring(vm, html.c_str()); + be_return(vm); + } + be_raise(vm, kTypeError, nullptr); + } + // Berry: `webserver.args() -> int` // // Returns the number of arguments