mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
Sanitize control codes in JSON code.
This commit is contained in:
parent
23177e9395
commit
2250ad7027
2 changed files with 5 additions and 8 deletions
9
format.c
9
format.c
|
@ -179,15 +179,8 @@ d_char *sanitize(const char *content)
|
||||||
xs *sl;
|
xs *sl;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
char *p, *v;
|
char *p, *v;
|
||||||
xs *content2 = xs_dup(content);
|
|
||||||
|
|
||||||
/* strip dangerous control codes */
|
sl = xs_regex_split(content, "</?[^>]+>");
|
||||||
for (n = 0; content2[n]; n++) {
|
|
||||||
if (xs_type(&content2[n]) != XSTYPE_STRING)
|
|
||||||
content2[n] = ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
sl = xs_regex_split(content2, "</?[^>]+>");
|
|
||||||
|
|
||||||
p = sl;
|
p = sl;
|
||||||
|
|
||||||
|
|
|
@ -260,6 +260,10 @@ static xs_val *_xs_json_loads_lexer(const char **json, js_type *t)
|
||||||
else
|
else
|
||||||
cp = i;
|
cp = i;
|
||||||
|
|
||||||
|
/* replace dangerous control codes with the replacement char */
|
||||||
|
if (cp >= '\0' && cp < ' ' && !strchr("\r\n\t", cp))
|
||||||
|
cp = 0xfffd;
|
||||||
|
|
||||||
v = xs_utf8_enc(v, cp);
|
v = xs_utf8_enc(v, cp);
|
||||||
c = '\0';
|
c = '\0';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue