summaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-07-11 19:45:58 +0200
committerdefault <nobody@localhost>2023-07-11 19:45:58 +0200
commit1c5a6894579924cb4d35e41ba3f140797a89c083 (patch)
tree839d36778afd953a18b1203f160c8ffc99949365 /format.c
parenta5272a21e6e5d288fd0fc5f6de65051fd40910b3 (diff)
Fixed some memory leaks.
Diffstat (limited to 'format.c')
-rw-r--r--format.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/format.c b/format.c
index 482edce..4491ae0 100644
--- a/format.c
+++ b/format.c
@@ -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, "&", "&amp;");
+ encoded = xs_replace_i(encoded, "<", "&lt;");
+ encoded = xs_replace_i(encoded, ">", "&gt;");
+ encoded = xs_replace_i(encoded, "\"", "&#34;");
+ encoded = xs_replace_i(encoded, "'", "&#39;");
+
+ /* Restore only <br>. Probably safe. Let's hope nothing goes wrong with this. */
+ encoded = xs_replace_i(encoded, "&lt;br&gt;", "<br>");
+
+ return encoded;
+}