[vlc-devel] [PATCH 1/2] lua/libs/input: fix 17611: properly populate filename attribute

Filip Roséen filip at atch.se
Sun Nov 6 16:38:04 CET 2016


The previous implementations usage of input_item_GetName resulted in
unexpected data in the filename attribute (given that
input_item_GetName will first query vlc_meta_Title, and if present
return that).

These changes extracts the filename for a given item, including
support for trailing slashes (so that we do not get an empty filename
for a path such as file:///media/).

fixes #17611
---
 modules/lua/libs/input.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/modules/lua/libs/input.c b/modules/lua/libs/input.c
index be1adf3..1887676 100644
--- a/modules/lua/libs/input.c
+++ b/modules/lua/libs/input.c
@@ -114,13 +114,24 @@ static int vlclua_input_metas_internal( lua_State *L, input_item_t *p_item )
     }
 
     lua_newtable( L );
-    char *psz_name;
     const char *psz_meta;
 
-    psz_name = input_item_GetName( p_item );
-    lua_pushstring( L, psz_name );
+    char* psz_uri = input_item_GetURI( p_item );
+    char* psz_filename = psz_uri ? strrchr( psz_uri, '/' ) : NULL;
+
+    if( psz_filename && psz_filename[1] == '\0' )
+    {
+        psz_filename[0] = '\0';
+        psz_filename = strrchr( psz_uri, '/' );
+    }
+
+    if( psz_filename )
+        ++psz_filename; /* skip slash */
+
+    lua_pushstring( L, psz_filename );
     lua_setfield( L, -2, "filename" );
-    free( psz_name );
+
+    free( psz_uri );
 
 #define PUSH_META( n, m ) \
     psz_meta = vlc_meta_Get( p_item->p_meta, vlc_meta_ ## n ); \
-- 
2.10.2



More information about the vlc-devel mailing list