diff options
author | Jan Ekström <jan.ekstrom@24i.com> | 2020-11-16 09:46:42 +0200 |
---|---|---|
committer | Jan Ekström <jeebjp@gmail.com> | 2021-03-05 19:45:00 +0200 |
commit | c8c6c9f5d96789001ea628f44cc5602bdc41d5f3 (patch) | |
tree | ae89062c92bad59c61150a566ce9e909ffb5da04 /fftools | |
parent | 0f6bf94eb71c2d5e996c89c290f1a53660c46c2e (diff) | |
download | ffmpeg-c8c6c9f5d96789001ea628f44cc5602bdc41d5f3.tar.gz |
ffprobe: switch to av_bprint_escape for XML escaping
Additionally update the result of the ffprobe XML writing test.
Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
Diffstat (limited to 'fftools')
-rw-r--r-- | fftools/ffprobe.c | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 740e759958..1eb9d88b5e 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -1672,24 +1672,6 @@ static av_cold int xml_init(WriterContext *wctx) return 0; } -static const char *xml_escape_str(AVBPrint *dst, const char *src, void *log_ctx) -{ - const char *p; - - for (p = src; *p; p++) { - switch (*p) { - case '&' : av_bprintf(dst, "%s", "&"); break; - case '<' : av_bprintf(dst, "%s", "<"); break; - case '>' : av_bprintf(dst, "%s", ">"); break; - case '"' : av_bprintf(dst, "%s", """); break; - case '\'': av_bprintf(dst, "%s", "'"); break; - default: av_bprint_chars(dst, *p, 1); - } - } - - return dst->str; -} - #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ') static void xml_print_section_header(WriterContext *wctx) @@ -1761,14 +1743,22 @@ static void xml_print_str(WriterContext *wctx, const char *key, const char *valu if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) { XML_INDENT(); + av_bprint_escape(&buf, key, NULL, + AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); printf("<%s key=\"%s\"", - section->element_name, xml_escape_str(&buf, key, wctx)); + section->element_name, buf.str); av_bprint_clear(&buf); - printf(" value=\"%s\"/>\n", xml_escape_str(&buf, value, wctx)); + + av_bprint_escape(&buf, value, NULL, + AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); + printf(" value=\"%s\"/>\n", buf.str); } else { if (wctx->nb_item[wctx->level]) printf(" "); - printf("%s=\"%s\"", key, xml_escape_str(&buf, value, wctx)); + + av_bprint_escape(&buf, value, NULL, + AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); + printf("%s=\"%s\"", key, buf.str); } av_bprint_finalize(&buf, NULL); |