diff mbox

[FFmpeg-devel,4/5] lavc/webvttenc: XML-escape text output

Message ID 20170412071127.60511-4-rodger.combs@gmail.com
State Withdrawn, archived
Headers show

Commit Message

Rodger Combs April 12, 2017, 7:11 a.m. UTC
The test output was previously incorrect, so the reference is updated.
---
 libavcodec/webvttenc.c       |  7 ++++++-
 tests/ref/fate/sub-webvttenc | 20 ++++++++++----------
 2 files changed, 16 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c
index c84bbf4b4e..0f51e73012 100644
--- a/libavcodec/webvttenc.c
+++ b/libavcodec/webvttenc.c
@@ -112,7 +112,12 @@  static void webvtt_style_apply(WebVTTContext *s, const char *style)
 static void webvtt_text_cb(void *priv, const char *text, int len)
 {
     WebVTTContext *s = priv;
-    av_bprint_append_data(&s->buffer, text, len);
+    char *buf = av_strndup(text, len);
+    if (!buf)
+        return;
+
+    av_bprint_escape(&s->buffer, buf, NULL, AV_ESCAPE_MODE_XML, 0);
+    av_free(buf);
 }
 
 static void webvtt_new_line_cb(void *priv, int forced)
diff --git a/tests/ref/fate/sub-webvttenc b/tests/ref/fate/sub-webvttenc
index ba567c33f6..08903e3a9d 100644
--- a/tests/ref/fate/sub-webvttenc
+++ b/tests/ref/fate/sub-webvttenc
@@ -36,18 +36,18 @@  This line should be strikethrough
 should be underline</u>
 
 00:14.501 --> 00:17.500
->
+&gt;
 It would be a good thing to
 hide invalid html tags that are closed and show the text in them
-<invalid_tag_unclosed>but show un-closed invalid html tags
-Show not opened tags</invalid_tag_not_opened>
-<
+&lt;invalid_tag_unclosed&gt;but show un-closed invalid html tags
+Show not opened tags&lt;/invalid_tag_not_opened&gt;
+&lt;
 
 00:17.501 --> 00:20.500
 and also
 hide invalid html tags with parameters that are closed and show the text in them
-<invalid_tag_uc par=5>but show un-closed invalid html tags
-<u>This text should be showed underlined without problems also: 2<3,5>1,4<6</u>
+&lt;invalid_tag_uc par=5&gt;but show un-closed invalid html tags
+<u>This text should be showed underlined without problems also: 2&lt;3,5&gt;1,4&lt;6</u>
 This shouldn't be underlined
 
 00:20.501 --> 00:21.500
@@ -164,14 +164,14 @@  should be hidden.
 
 01:02.501 --> 01:04.500
 It shouldn't be strikethrough,
-not opened tag showed as text.</s>
-Not opened tag showed as text.</xxxxx>
+not opened tag showed as text.&lt;/s&gt;
+Not opened tag showed as text.&lt;/xxxxx&gt;
 
 01:04.501 --> 01:06.500
 Three lines should be strikethrough,
 yes.
-<yyyy>Not closed tags showed as text
+&lt;yyyy&gt;Not closed tags showed as text
 
 01:06.501 --> 01:08.500
 Both line should be strikethrough but
-the wrong closing tag should be showed</b>
+the wrong closing tag should be showed&lt;/b&gt;