Skip to content

Commit cbeb9a2

Browse files
Sanitize control characters in textbox input (#144)
Signed-off-by: Marek Maškarinec <[email protected]>
1 parent 49e999f commit cbeb9a2

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/staembed.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "tophat.h"
1+
#include "tophat.h"
22
const char *th_em_modulesrc[] = {
33
"\n"
44
"import (\n"
@@ -534,7 +534,9 @@ const char *th_em_modulesrc[] = {
534534
"\n"
535535
"fn umth_image_render_target_to_image(ret: ^Image, rt: RenderTarget)\n"
536536
"//~~fn RenderTarget.toImage\n"
537-
"// Returns the image of the render target.\n"
537+
"// Returns the image of the render target. The resulting image has the same\n"
538+
"// lifetime as the base RenderTarget. If you need to use it past the lifetime\n"
539+
"// of the RenderTarget, use the copy method.\n"
538540
"// Do not call `setfilter` on the resulting image.\n"
539541
"fn (rt: ^RenderTarget) toImage*(): Image {\n"
540542
"//~~\n"
@@ -3720,6 +3722,13 @@ const char *th_em_modulesrc[] = {
37203722
"\t\t}\n"
37213723
"\n"
37223724
"\t\trunes := utf8.decode(input.getStr())\n"
3725+
"\t\tfor i:=0; i < len(runes); i++ {\n"
3726+
"\t\t\tif runes[i] < 32 {\n"
3727+
"\t\t\t\trunes = delete(runes, i)\n"
3728+
"\t\t\t\ti--\n"
3729+
"\t\t\t}\n"
3730+
"\t\t}\n"
3731+
"\n"
37233732
"\t\tif len(runes) > 0 && v {\n"
37243733
"\t\t\ttb.buffer = append(append(slice(tb.buffer, 0, tb.cursor), runes), slice(tb.buffer, tb.cursor))\n"
37253734
"\t\t\ttb.cursor += len(runes)\n"
@@ -4251,7 +4260,9 @@ const char *th_em_moduledocs[] = {
42514260
"fn (rt: ^RenderTarget) toImage*(): Image {\n"
42524261
"```\n"
42534262
"\n"
4254-
"Returns the image of the render target.\n"
4263+
"Returns the image of the render target. The resulting image has the same\n"
4264+
"lifetime as the base RenderTarget. If you need to use it past the lifetime\n"
4265+
"of the RenderTarget, use the copy method.\n"
42554266
"Do not call `setfilter` on the resulting image.\n"
42564267
"\n"
42574268
"\n"

umka/ui.um

+7
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,13 @@ fn (gui: ^Gui) textBox*(tb: ^TextBox, cfg: TextBoxConfig = {}) {
790790
}
791791

792792
runes := utf8.decode(input.getStr())
793+
for i:=0; i < len(runes); i++ {
794+
if runes[i] < 32 {
795+
runes = delete(runes, i)
796+
i--
797+
}
798+
}
799+
793800
if len(runes) > 0 && v {
794801
tb.buffer = append(append(slice(tb.buffer, 0, tb.cursor), runes), slice(tb.buffer, tb.cursor))
795802
tb.cursor += len(runes)

0 commit comments

Comments
 (0)