mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
In sanitize(), rebuild the accepted tags with only the accepted attributes.
This commit is contained in:
parent
236ca9af6b
commit
bdc689e594
1 changed files with 10 additions and 5 deletions
15
format.c
15
format.c
|
@ -185,6 +185,7 @@ d_char *sanitize(const char *content)
|
||||||
xs *s1 = xs_strip(xs_crop(xs_dup(v), v[1] == '/' ? 2 : 1, -1));
|
xs *s1 = xs_strip(xs_crop(xs_dup(v), v[1] == '/' ? 2 : 1, -1));
|
||||||
xs *l1 = xs_split_n(s1, " ", 1);
|
xs *l1 = xs_split_n(s1, " ", 1);
|
||||||
xs *tag = xs_tolower(xs_dup(xs_list_get(l1, 0)));
|
xs *tag = xs_tolower(xs_dup(xs_list_get(l1, 0)));
|
||||||
|
xs *s2 = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* check if it's one of the valid tags */
|
/* check if it's one of the valid tags */
|
||||||
|
@ -194,14 +195,18 @@ d_char *sanitize(const char *content)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid_tags[i]) {
|
if (valid_tags[i]) {
|
||||||
/* accepted tag */
|
/* accepted tag: rebuild it with only the accepted elements */
|
||||||
s = xs_str_cat(s, v);
|
xs *el = xs_regex_match(v, "(href|rel|class|target)=\"[^\"]*\"");
|
||||||
|
xs *s3 = xs_join(el, " ");
|
||||||
|
|
||||||
|
s2 = xs_fmt("<%s%s %s>", v[1] == '/' ? "/" : "", tag, s3);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* bad tag */
|
/* bad tag: escape it */
|
||||||
xs *s2 = xs_replace(v, "<", "<");
|
s2 = xs_replace(v, "<", "<");
|
||||||
s = xs_str_cat(s, s2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s = xs_str_cat(s, s2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* non-tag */
|
/* non-tag */
|
||||||
|
|
Loading…
Reference in a new issue