Browse Source

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>
tags/n4.4
Jan Ekström Jan Ekström 5 years ago
parent
commit
c8c6c9f5d9
2 changed files with 12 additions and 22 deletions
  1. +11
    -21
      fftools/ffprobe.c
  2. +1
    -1
      tests/ref/fate/ffprobe_xml

+ 11
- 21
fftools/ffprobe.c View File

@@ -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", "&amp;"); break;
case '<' : av_bprintf(dst, "%s", "&lt;"); break;
case '>' : av_bprintf(dst, "%s", "&gt;"); break;
case '"' : av_bprintf(dst, "%s", "&quot;"); break;
case '\'': av_bprintf(dst, "%s", "&apos;"); 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);


+ 1
- 1
tests/ref/fate/ffprobe_xml View File

@@ -51,7 +51,7 @@

<format filename="tests/data/ffprobe-test.nut" nb_streams="3" nb_programs="0" format_name="nut" start_time="0.000000" duration="0.120000" size="1053624" bit_rate="70241600" probe_score="100">
<tag key="title" value="ffprobe test file"/>
<tag key="comment" value="&apos;A comment with CSV, XML &amp; JSON special chars&apos;: &lt;tag value=&quot;x&quot;&gt;"/>
<tag key="comment" value="'A comment with CSV, XML &amp; JSON special chars': &lt;tag value=&quot;x&quot;&gt;"/>
<tag key="comment2" value="I ♥ Üñîçød€"/>
</format>
</ffprobe>

Loading…
Cancel
Save