diff mbox series

[FFmpeg-devel,2/3] ffprobe: switch to av_bprint_escape for XML escaping

Message ID 20201204144643.73279-3-jeebjp@gmail.com
State Superseded
Headers show
Series Initial implementation of TTML encoding/muxing | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Jan Ekström Dec. 4, 2020, 2:46 p.m. UTC
From: Jan Ekström <jan.ekstrom@24i.com>

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
---
 fftools/ffprobe.c | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)

Comments

Nicolas George Dec. 7, 2020, 1:16 p.m. UTC | #1
Jan Ekström (12020-12-04):
> From: Jan Ekström <jan.ekstrom@24i.com>
> 
> Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
> ---
>  fftools/ffprobe.c | 29 ++++++++---------------------
>  1 file changed, 8 insertions(+), 21 deletions(-)

Should be ok.

Regards,
diff mbox series

Patch

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 86bd23d36d..a127a3f9bb 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -1671,24 +1671,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)
@@ -1760,14 +1742,19 @@  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, 0);
         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, 0);
+        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, 0);
+        printf("%s=\"%s\"", key, buf.str);
     }
 
     av_bprint_finalize(&buf, NULL);