Change uri functions to work with valid Windows file uri's

Windows file uri's can be of the form 'file:///N:/bob.txt' so change
the gnc_uri_get_components to remove a left over '/' at the start so
gnc_resolve_file_path gets the absolute path correctly. Also change
gnc_uri_create_uri to add an extra '/' for Windows file uri's.
This commit is contained in:
Robert Fewell 2019-03-29 17:34:45 +00:00
parent 89d2cde979
commit 5eb6f76e63

View File

@ -176,7 +176,15 @@ void gnc_uri_get_components (const gchar *uri,
if ( gnc_uri_is_file_scheme ( *scheme ) )
{
*path = gnc_resolve_file_path ( splituri[1] );
/* a true file uri on windows can start file:///N:/
so we come here with /N:/ */
if (g_str_has_prefix (splituri[1], "/") && g_strstr_len (splituri[1], -1, ":") != NULL)
{
gchar *ptr = splituri[1];
*path = gnc_resolve_file_path ( ptr + 1 );
}
else
*path = gnc_resolve_file_path ( splituri[1] );
g_strfreev ( splituri );
return;
}
@ -304,15 +312,25 @@ gchar *gnc_uri_create_uri (const gchar *scheme,
* path info as is.
*/
gchar *abs_path;
gchar *uri_scheme;
if (scheme && (!gnc_uri_is_known_scheme (scheme)) )
abs_path = g_strdup ( path );
else
abs_path = gnc_resolve_file_path ( path );
if ( scheme == NULL )
uri = g_strdup_printf ( "file://%s", abs_path );
if (!scheme)
uri_scheme = g_strdup ("file");
else
uri = g_strdup_printf ( "%s://%s", scheme, abs_path );
uri_scheme = g_strdup (scheme);
if (g_str_has_prefix (abs_path, "/"))
uri = g_strdup_printf ( "%s://%s", uri_scheme, abs_path );
else // for windows add an extra "/"
uri = g_strdup_printf ( "%s:///%s", uri_scheme, abs_path );
g_free (uri_scheme);
g_free (abs_path);
return uri;
}