diff options
| author | 2023-07-11 19:45:58 +0200 | |
|---|---|---|
| committer | 2023-07-11 19:45:58 +0200 | |
| commit | 1c5a6894579924cb4d35e41ba3f140797a89c083 (patch) | |
| tree | 839d36778afd953a18b1203f160c8ffc99949365 /xs.h | |
| parent | Merge pull request 'Attempt to prevent XSS.' (#64) from yonle/snac2:master in... (diff) | |
| download | snac2-1c5a6894579924cb4d35e41ba3f140797a89c083.tar.gz snac2-1c5a6894579924cb4d35e41ba3f140797a89c083.tar.xz snac2-1c5a6894579924cb4d35e41ba3f140797a89c083.zip | |
Fixed some memory leaks.
Diffstat (limited to 'xs.h')
| -rw-r--r-- | xs.h | 15 |
1 files changed, 0 insertions, 15 deletions
| @@ -72,7 +72,6 @@ xs_str *xs_replace_in(xs_str *str, const char *sfrom, const char *sto, int times | |||
| 72 | xs_str *xs_fmt(const char *fmt, ...); | 72 | xs_str *xs_fmt(const char *fmt, ...); |
| 73 | int xs_str_in(const char *haystack, const char *needle); | 73 | int xs_str_in(const char *haystack, const char *needle); |
| 74 | int _xs_startsorends(const char *str, const char *xfix, int ends); | 74 | int _xs_startsorends(const char *str, const char *xfix, int ends); |
| 75 | xs_str *xs_encode_html(const xs_str *str); | ||
| 76 | #define xs_startswith(str, prefix) _xs_startsorends(str, prefix, 0) | 75 | #define xs_startswith(str, prefix) _xs_startsorends(str, prefix, 0) |
| 77 | #define xs_endswith(str, postfix) _xs_startsorends(str, postfix, 1) | 76 | #define xs_endswith(str, postfix) _xs_startsorends(str, postfix, 1) |
| 78 | xs_str *xs_crop_i(xs_str *str, int start, int end); | 77 | xs_str *xs_crop_i(xs_str *str, int start, int end); |
| @@ -507,20 +506,6 @@ int _xs_startsorends(const char *str, const char *xfix, int ends) | |||
| 507 | return !!(ssz >= psz && memcmp(xfix, str + (ends ? ssz - psz : 0), psz) == 0); | 506 | return !!(ssz >= psz && memcmp(xfix, str + (ends ? ssz - psz : 0), psz) == 0); |
| 508 | } | 507 | } |
| 509 | 508 | ||
| 510 | xs_str *xs_encode_html(const char *str) | ||
| 511 | /* escapes html characters */ | ||
| 512 | { | ||
| 513 | xs_str *encoded = xs_replace(str, "&", "&"); | ||
| 514 | encoded = xs_replace(encoded, "<", "<"); | ||
| 515 | encoded = xs_replace(encoded, ">", ">"); | ||
| 516 | encoded = xs_replace(encoded, "\"", """); | ||
| 517 | encoded = xs_replace(encoded, "'", "'"); | ||
| 518 | |||
| 519 | // Restore only <br>. Probably safe. Let's hope nothing goes wrong with this. | ||
| 520 | encoded = xs_replace(encoded, "<br>", "<br>"); | ||
| 521 | |||
| 522 | return encoded; | ||
| 523 | } | ||
| 524 | 509 | ||
| 525 | xs_str *xs_crop_i(xs_str *str, int start, int end) | 510 | xs_str *xs_crop_i(xs_str *str, int start, int end) |
| 526 | /* crops the d_char to be only from start to end */ | 511 | /* crops the d_char to be only from start to end */ |