From a80b1120f1fa19cfb036e371313af8e73eaea049 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 14 Jan 2008 14:55:27 +0000 Subject: [PATCH] Handle root correctly in g_file_get_relative_path (#508719) 2008-01-14 Alexander Larsson * glocalfile.c: (match_prefix): Handle root correctly in g_file_get_relative_path (#508719) svn path=/trunk/; revision=6305 --- gio/ChangeLog | 6 ++++++ gio/glocalfile.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/gio/ChangeLog b/gio/ChangeLog index ecb52eb2d..5a7ae0aae 100644 --- a/gio/ChangeLog +++ b/gio/ChangeLog @@ -1,3 +1,9 @@ +2008-01-14 Alexander Larsson + + * glocalfile.c: + (match_prefix): + Handle root correctly in g_file_get_relative_path (#508719) + 2008-01-14 Alexander Larsson * gasyncresult.c: diff --git a/gio/glocalfile.c b/gio/glocalfile.c index 35ad6ed79..1de3e485d 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -475,6 +475,13 @@ match_prefix (const char *path, prefix_len = strlen (prefix); if (strncmp (path, prefix, prefix_len) != 0) return NULL; + + /* Handle the case where prefix is the root, so that + * the IS_DIR_SEPRARATOR check below works */ + if (prefix_len > 0 && + G_IS_DIR_SEPARATOR (prefix[prefix_len-1])) + prefix_len--; + return path + prefix_len; }