[FFmpeg-cvslog] lavc/htmlsubtitles: improve line breaks handling

Clément Bœsch git at videolan.org
Tue Aug 1 17:08:52 EEST 2017


ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Sat Jul 29 21:09:54 2017 +0200| [e80037186327f97fffad75161e7d71cd9f5685f6] | committer: Clément Bœsch

lavc/htmlsubtitles: improve line breaks handling

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e80037186327f97fffad75161e7d71cd9f5685f6
---

 libavcodec/htmlsubtitles.c              | 5 +++--
 libavcodec/tests/htmlsubtitles.c        | 2 ++
 tests/ref/fate/libavcodec-htmlsubtitles | 1 +
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavcodec/htmlsubtitles.c b/libavcodec/htmlsubtitles.c
index baed28450e..ae2c48b501 100644
--- a/libavcodec/htmlsubtitles.c
+++ b/libavcodec/htmlsubtitles.c
@@ -165,7 +165,7 @@ int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in)
 #define LIKELY_A_TAG_CHAR(x) (((x) >= '0' && (x) <= '9') || \
                               ((x) >= 'a' && (x) <= 'z') || \
                               ((x) >= 'A' && (x) <= 'Z') || \
-                               (x) == '_')
+                               (x) == '_' || (x) == '/')
                 for (i = 0; tagname[i]; i++) {
                     if (!LIKELY_A_TAG_CHAR(tagname[i])) {
                         likely_a_tag = 0;
@@ -237,7 +237,8 @@ int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in)
                     } else if (tagname[0] && !tagname[1] && strchr("bisu", av_tolower(tagname[0]))) {
                         av_bprintf(dst, "{\\%c%d}", (char)av_tolower(tagname[0]), !tag_close);
                         in += skip;
-                    } else if (!av_strcasecmp(tagname, "br")) {
+                    } else if (!av_strncasecmp(tagname, "br", 2) &&
+                               (!tagname[2] || (tagname[2] == '/' && !tagname[3]))) {
                         av_bprintf(dst, "\\N");
                         in += skip;
                     } else if (likely_a_tag) {
diff --git a/libavcodec/tests/htmlsubtitles.c b/libavcodec/tests/htmlsubtitles.c
index d0b55a45d3..7c89ee97af 100644
--- a/libavcodec/tests/htmlsubtitles.c
+++ b/libavcodec/tests/htmlsubtitles.c
@@ -29,6 +29,8 @@ static const char * const test_cases[] = {
     "Foo <foo at bar.com>",                    // not a tag (not alnum)
 
     "<b> foo <I> bar </B> bla </i>",        // broken nesting
+
+    "A<br>B<BR/>C<br  / >D<  Br >E<brk><brk/>", // misc line breaks
 };
 
 int main(void)
diff --git a/tests/ref/fate/libavcodec-htmlsubtitles b/tests/ref/fate/libavcodec-htmlsubtitles
index 702f0b7ea3..66dd8e8d48 100644
--- a/tests/ref/fate/libavcodec-htmlsubtitles
+++ b/tests/ref/fate/libavcodec-htmlsubtitles
@@ -5,3 +5,4 @@
 < font color=red >red</font> --> {\c&HFF&}red{\c}
 Foo <foo at bar.com> --> Foo <foo at bar.com>
 <b> foo <I> bar </B> bla </i> --> {\b1} foo {\i1} bar {\b0} bla {\i0}
+A<br>B<BR/>C<br  / >D<  Br >E<brk><brk/> --> A\NB\NC\ND\NE



More information about the ffmpeg-cvslog mailing list