[vlc-commits] lua/libs/input: fix 17611: properly populate filename attribute
Filip Roséen
git at videolan.org
Thu Nov 10 07:35:43 CET 2016
vlc | branch: master | Filip Roséen <filip at atch.se> | Thu Nov 10 07:34:28 2016 +0100| [75215c73282f43881d9696f32e92eee147cfce96] | committer: Pierre Ynard
lua/libs/input: fix 17611: properly populate filename attribute
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
Signed-off-by: Pierre Ynard <linkfanel at yahoo.fr>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=75215c73282f43881d9696f32e92eee147cfce96
---
modules/lua/libs/input.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/modules/lua/libs/input.c b/modules/lua/libs/input.c
index be1adf3..6d14ebc 100644
--- a/modules/lua/libs/input.c
+++ b/modules/lua/libs/input.c
@@ -34,7 +34,7 @@
#include <vlc_common.h>
#include <vlc_meta.h>
-
+#include <vlc_url.h>
#include <vlc_playlist.h>
#include <assert.h>
@@ -114,13 +114,28 @@ 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' )
+ {
+ /* trailing slash, get the preceeding data */
+ psz_filename[0] = '\0';
+ psz_filename = strrchr( psz_uri, '/' );
+ }
+
+ if( psz_filename )
+ {
+ /* url decode, without leading slash */
+ psz_filename = vlc_uri_decode( psz_filename + 1 );
+ }
+
+ 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 ); \
More information about the vlc-commits
mailing list