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