Berry `webserver.html_escape()` reusing the internal HTML escaping function (#18381)

This commit is contained in:
s-hadinger 2023-04-10 19:16:01 +02:00 committed by GitHub
parent 0328915eab
commit 6007f2d970
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View File

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

View File

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

View File

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