diff options
author | default <nobody@localhost> | 2023-07-11 19:45:58 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2023-07-11 19:45:58 +0200 |
commit | 1c5a6894579924cb4d35e41ba3f140797a89c083 (patch) | |
tree | 839d36778afd953a18b1203f160c8ffc99949365 /format.c | |
parent | a5272a21e6e5d288fd0fc5f6de65051fd40910b3 (diff) |
Fixed some memory leaks.
Diffstat (limited to 'format.c')
-rw-r--r-- | format.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -238,3 +238,19 @@ xs_str *sanitize(const char *content) return s; } + + +xs_str *encode_html(const char *str) +/* escapes html characters */ +{ + xs_str *encoded = xs_replace(str, "&", "&"); + encoded = xs_replace_i(encoded, "<", "<"); + encoded = xs_replace_i(encoded, ">", ">"); + encoded = xs_replace_i(encoded, "\"", """); + encoded = xs_replace_i(encoded, "'", "'"); + + /* Restore only <br>. Probably safe. Let's hope nothing goes wrong with this. */ + encoded = xs_replace_i(encoded, "<br>", "<br>"); + + return encoded; +} |