summaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
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)
238 238
239 return s; 239 return s;
240} 240}
241
242
243xs_str *encode_html(const char *str)
244/* escapes html characters */
245{
246 xs_str *encoded = xs_replace(str, "&", "&");
247 encoded = xs_replace_i(encoded, "<", "&lt;");
248 encoded = xs_replace_i(encoded, ">", "&gt;");
249 encoded = xs_replace_i(encoded, "\"", "&#34;");
250 encoded = xs_replace_i(encoded, "'", "&#39;");
251
252 /* Restore only <br>. Probably safe. Let's hope nothing goes wrong with this. */
253 encoded = xs_replace_i(encoded, "&lt;br&gt;", "<br>");
254
255 return encoded;
256}