Commit fc5954ab authored by Rafaël Carré's avatar Rafaël Carré

xspf writer: do percent encoding on more characters when we have a file:// URI.

We don't do that on other URIs because those characters may be used as delimiters, and must not be percent encoded.

Now produces valid XSPF-1 files.
parent 50768f14
...@@ -283,7 +283,7 @@ static char *assertUTF8URI( char *psz_name ) ...@@ -283,7 +283,7 @@ static char *assertUTF8URI( char *psz_name )
{ {
char *psz_ret = NULL; /**< the new result buffer to return */ char *psz_ret = NULL; /**< the new result buffer to return */
char *psz_s = NULL, *psz_d = NULL; /**< src & dest pointers for URI conversion */ char *psz_s = NULL, *psz_d = NULL; /**< src & dest pointers for URI conversion */
vlc_bool_t b_name_is_uri = VLC_FALSE; vlc_bool_t b_uri_is_file = VLC_FALSE; /**< we do additional %-encoding if the URI is a file:// one */
if( !psz_name || !*psz_name ) if( !psz_name || !*psz_name )
return NULL; return NULL;
...@@ -300,16 +300,22 @@ static char *assertUTF8URI( char *psz_name ) ...@@ -300,16 +300,22 @@ static char *assertUTF8URI( char *psz_name )
return NULL; return NULL;
/** \todo check for a valid scheme part preceding the colon */ /** \todo check for a valid scheme part preceding the colon */
if( strchr( psz_s, ':' ) ) size_t i_delim = strcspn( psz_s, ":" );
if( i_delim != strlen( psz_s ) )
{ {
psz_d = psz_ret; i_delim++; /* skip the ':' */
b_name_is_uri = VLC_TRUE; strncpy( psz_ret, psz_s, i_delim );
psz_d = psz_ret + i_delim;
if( !strncmp( psz_s, "file://", 7 ) )
b_uri_is_file = VLC_TRUE;
} }
/* assume "file" scheme if no scheme-part is included */ /* assume "file" scheme if no scheme-part is included */
else else
{ {
strcpy( psz_ret, "file://" ); strcpy( psz_ret, "file://" );
psz_d = psz_ret + 7; psz_d = psz_ret + 7;
b_uri_is_file = VLC_TRUE;
} }
while( *psz_s ) while( *psz_s )
...@@ -320,7 +326,17 @@ static char *assertUTF8URI( char *psz_name ) ...@@ -320,7 +326,17 @@ static char *assertUTF8URI( char *psz_name )
*psz_s == '>' || *psz_s == '>' ||
*psz_s == '&' || *psz_s == '&' ||
*psz_s == ' ' || *psz_s == ' ' ||
( *psz_s == '%' && !b_name_is_uri ) ) ( b_uri_is_file && (
*psz_s == ':' ||
*psz_s == '"' ||
*psz_s == '?' ||
*psz_s == '#' ||
*psz_s == '[' ||
*psz_s == ']' ||
*psz_s == '@' ||
*psz_s == '%' )
)
)
{ {
*psz_d++ = '%'; *psz_d++ = '%';
*psz_d++ = hexchars[(*psz_s >> 4) & B00001111]; *psz_d++ = hexchars[(*psz_s >> 4) & B00001111];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment