json_dumper: escape forward slash in some strings

If the JSON output is written in a script tag for a HTML page, be sure
to not to break it.

Change-Id: I1b9ba6a39faf266e8a7bf9befa2899978beb130c
Reviewed-on: https://code.wireshark.org/review/31953
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Peter Wu 2019-02-10 00:34:32 +01:00 committed by Anders Broman
parent 329e54010b
commit 089d432040
1 changed files with 3 additions and 0 deletions

View File

@ -60,6 +60,9 @@ json_puts_string(FILE *fp, const char *str, gboolean dot_to_underscore)
if ((guint)str[i] < 0x20) {
fputc('\\', fp);
fputs(json_cntrl[(guint)str[i]], fp);
} else if (i > 0 && str[i - 1] == '<' && str[i] == '/') {
// Convert </script> to <\/script> to avoid breaking web pages.
fputs("\\/", fp);
} else {
if (str[i] == '\\' || str[i] == '"') {
fputc('\\', fp);