diff --git a/ChangeLog b/ChangeLog index c37f8705be..3be8e44f9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-02-10 Tim-Philipp Müller + + * gst/subparse/gstsubparse.c: (subrip_remove_unhandled_tag), + (subrip_remove_unhandled_tags), (parse_subrip): + For SubRip (.srt) subtitles, ignore all markup tags we don't + handle (like font tags, for example). + + * tests/check/elements/subparse.c: + Add test for this. + 2007-02-09 Tim-Philipp Müller * gst/playback/gstdecodebin.c: (add_fakesink), diff --git a/gst/subparse/gstsubparse.c b/gst/subparse/gstsubparse.c index 779e728033..138ef46a66 100644 --- a/gst/subparse/gstsubparse.c +++ b/gst/subparse/gstsubparse.c @@ -547,6 +547,42 @@ subrip_unescape_formatting (gchar * txt) } } + +static gboolean +subrip_remove_unhandled_tag (gchar * start, gchar * stop) +{ + gchar *tag, saved; + + tag = start + strlen ("<"); + if (*tag == '/') + ++tag; + + if (g_ascii_tolower (*tag) < 'a' || g_ascii_tolower (*tag) > 'z') + return FALSE; + + saved = *stop; + *stop = '\0'; + GST_LOG ("removing unhandled tag '%s'", start); + *stop = saved; + g_memmove (start, stop, strlen (stop) + 1); + return TRUE; +} + +/* remove tags we haven't explicitly allowed earlier on, like font tags + * for example */ +static void +subrip_remove_unhandled_tags (gchar * txt) +{ + gchar *pos, *gt; + + for (pos = txt; pos != NULL && *pos != '\0'; ++pos) { + if (strncmp (pos, "<", 4) == 0 && (gt = strstr (pos + 4, ">"))) { + if (subrip_remove_unhandled_tag (pos, gt + strlen (">"))) + --pos; + } + } +} + /* we only allow , and , so let's take a simple approach. This code * assumes the input has been escaped and subrip_unescape_formatting() has then * been run over the input! This function adds missing closing markup tags and @@ -670,6 +706,7 @@ parse_subrip (ParserState * state, const gchar * line) g_string_truncate (state->buf, 0); state->state = 0; subrip_unescape_formatting (ret); + subrip_remove_unhandled_tags (ret); strip_trailing_newlines (ret); subrip_fix_up_markup (&ret); return ret; diff --git a/tests/check/elements/subparse.c b/tests/check/elements/subparse.c index 3cd7d3be8c..809f8d78b5 100644 --- a/tests/check/elements/subparse.c +++ b/tests/check/elements/subparse.c @@ -100,7 +100,10 @@ static SubParseInputChunk srt_input[] = { "26\n00:04:00,000 --> 00:05:00,000\nRock & Roll\n\n", 240 * GST_SECOND, 300 * GST_SECOND, "Rock & Roll"}, { "27\n00:06:00,000 --> 00:08:00,000\nRock & Roll\n\n", - 360 * GST_SECOND, 480 * GST_SECOND, "Rock & Roll"} + 360 * GST_SECOND, 480 * GST_SECOND, "Rock & Roll"}, { + "28\n00:10:00,000 --> 00:11:00,000\n" + "This is in blue but <5\n\n", + 600 * GST_SECOND, 660 * GST_SECOND, "This is in blue but <5"} }; static void