diff options
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; +} |