From f6062d43e84e86a1269c41d4136e5098e15173b2 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sun, 5 Jul 2009 20:47:33 +0200 Subject: [PATCH] Don't replace ~ when we shouldn't Bump glib req to 2.14 to get GRegex, now we only replace ~ with your homedir in an action if it is (at the start of the string or preceded by whitespace) and (at the end of the string or followed by (whitespace or a slash)). (?:^|(?<=[ \t]))~(?=[/ \t$]) --- configure.ac | 2 +- obt/paths.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index b96681a5..0c083a59 100644 --- a/configure.ac +++ b/configure.ac @@ -94,7 +94,7 @@ if test "$SED" = "no"; then AC_MSG_ERROR([The program "sed" is not available. This program is required to build Openbox.]) fi -PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.6.0]) +PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.14.0]) AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_LIBS) diff --git a/obt/paths.c b/obt/paths.c index 61004998..68615433 100644 --- a/obt/paths.c +++ b/obt/paths.c @@ -169,14 +169,16 @@ void obt_paths_unref(ObtPaths *p) gchar *obt_paths_expand_tilde(const gchar *f) { - gchar **spl; gchar *ret; + GRegex *regex; if (!f) return NULL; - spl = g_strsplit(f, "~", 0); - ret = g_strjoinv(g_get_home_dir(), spl); - g_strfreev(spl); + + regex = g_regex_new("(?:^|(?<=[ \\t]))~(?=[/ \\t$])", G_REGEX_MULTILINE | G_REGEX_RAW, 0, NULL); + ret = g_regex_replace_literal(regex, f, -1, 0, g_get_home_dir(), 0, NULL); + g_regex_unref(regex); + return ret; } -- 2.34.1