Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
5c11b66b by François Cartegnie at 2024-01-26T13:18:56+00:00
codec: webvtt: fix empty newline insertion

- - - - -
a8abcc7d by François Cartegnie at 2024-01-26T13:18:56+00:00
codec: webvtt: use unicode line separator to encode empty line

- - - - -
0fe9d9bd by François Cartegnie at 2024-01-26T13:18:56+00:00
codec: webvtt: escape text when encoding

- - - - -


1 changed file:

- modules/codec/webvtt/encvtt.c


Changes:

=====================================
modules/codec/webvtt/encvtt.c
=====================================
@@ -46,6 +46,35 @@ int webvtt_OpenEncoder( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
+static void bo_add_escaped( bo_t *box, size_t len, const char *psz )
+{
+    if( likely(strcspn(psz, "&<>") >= len) )
+    {
+        bo_add_mem( box, len, psz );
+    }
+    else
+    {
+        for( size_t i=0; i<len; i++ )
+        {
+            switch(*psz)
+            {
+            case '&':
+                bo_add_mem( box, 6, "&#x26;" );
+                break;
+            case '<':
+                bo_add_mem( box, 6, "&#x3c;" );
+                break;
+            case '>': /* escapes forbidden --> sequence */
+                bo_add_mem( box, 6, "&#x3e;" );
+                break;
+            default:
+                bo_add_8( box, *psz );
+                break;
+            }
+            psz++;
+        }
+    }
+}
 
 static void WriteText( const char *psz, bo_t *box, char *c_last )
 {
@@ -56,9 +85,9 @@ static void WriteText( const char *psz, bo_t *box, char 
*c_last )
         const char *p = strchr( psz, '\n' );
         if( p )
         {
-            bo_add_mem( box, p - psz, psz );
-            if( *c_last == '\n' )
-                bo_add_8( box, '!' ); /* Add space */
+            bo_add_escaped( box, p - psz, psz );
+            if( (*c_last == '\n' || *c_last == '\0') && *psz == '\n' )
+                bo_add_mem( box, 8, "&#x2028;" ); /* Add space for empty line 
*/
             bo_add_8( box, '\n' );
             *c_last = '\n';
             psz = p + 1;
@@ -66,7 +95,7 @@ static void WriteText( const char *psz, bo_t *box, char 
*c_last )
         else
         {
             size_t len = strlen(psz);
-            bo_add_mem( box, len, psz );
+            bo_add_escaped( box, len, psz );
             *c_last = (len > 0) ? psz[len - 1] : '\0';
             break;
         }



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/3be620911f0fa70d8a922479ca1f70d75a5c5bba...0fe9d9bd7fb80c743049aaa1d7583bd15e30cef6

-- 
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/3be620911f0fa70d8a922479ca1f70d75a5c5bba...0fe9d9bd7fb80c743049aaa1d7583bd15e30cef6
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to