[FFmpeg-devel,3/5] ffprobe: switch xml_escape_str to use av_bprint_escape

Submitted by Rodger Combs on April 12, 2017, 7:11 a.m.

Details

Message ID 20170412071127.60511-3-rodger.combs@gmail.com
State New
Headers show

Commit Message

Rodger Combs April 12, 2017, 7:11 a.m.
This now escapes single-quotes, so the test reference is updated.
---
 ffprobe.c                  | 25 ++++++-------------------
 tests/ref/fate/ffprobe_xml |  2 +-
 2 files changed, 7 insertions(+), 20 deletions(-)

Comments

Nicolas George April 12, 2017, 1:25 p.m.
Le tridi 23 germinal, an CCXXV, Rodger Combs a écrit :
> This now escapes single-quotes, so the test reference is updated.
> ---
>  ffprobe.c                  | 25 ++++++-------------------
>  tests/ref/fate/ffprobe_xml |  2 +-
>  2 files changed, 7 insertions(+), 20 deletions(-)

Looks ok, but I do not maintain ffprobe.

Regards,

Patch hide | download patch | download mbox

diff --git a/ffprobe.c b/ffprobe.c
index 0a9ba14d8d..5c5bdaf3b1 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -1658,21 +1658,10 @@  static av_cold int xml_init(WriterContext *wctx)
     return 0;
 }
 
-static const char *xml_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
+static const char *xml_escape_str(AVBPrint *dst, const char *src)
 {
-    const char *p;
-
-    for (p = src; *p; p++) {
-        switch (*p) {
-        case '&' : av_bprintf(dst, "%s", "&");  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);
-        }
-    }
-
+    av_bprint_clear(dst);
+    av_bprint_escape(dst, src, NULL, AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_ESCAPE_DOUBLE_QUOTE);
     return dst->str;
 }
 
@@ -1747,14 +1736,12 @@  static void xml_print_str(WriterContext *wctx, const char *key, const char *valu
 
     if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
         XML_INDENT();
-        printf("<%s key=\"%s\"",
-               section->element_name, xml_escape_str(&buf, key, wctx));
-        av_bprint_clear(&buf);
-        printf(" value=\"%s\"/>\n", xml_escape_str(&buf, value, wctx));
+        printf("<%s key=\"%s\"", section->element_name, xml_escape_str(&buf, key));
+        printf(" value=\"%s\"/>\n", xml_escape_str(&buf, value));
     } else {
         if (wctx->nb_item[wctx->level])
             printf(" ");
-        printf("%s=\"%s\"", key, xml_escape_str(&buf, value, wctx));
+        printf("%s=\"%s\"", key, xml_escape_str(&buf, value));
     }
 
     av_bprint_finalize(&buf, NULL);
diff --git a/tests/ref/fate/ffprobe_xml b/tests/ref/fate/ffprobe_xml
index d2c5ecdf73..8abac000c9 100644
--- a/tests/ref/fate/ffprobe_xml
+++ b/tests/ref/fate/ffprobe_xml
@@ -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>