diff --git a/ChangeLog b/ChangeLog index 47929390..a877a494 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-04-28 Benno Schulenberg + * src/color.c (color_update): Match the file regex of a syntax against + the absolute, canonical path instead of against the path the user gave. + This fixes Savannah bug #44288, reported by Mike Frysinger. + 2015-04-25 Benno Schulenberg * src/search.c (do_replace_loop): Remove the unintended special case for replacing multiple occurrences of a literal ^ or $; see diff --git a/src/color.c b/src/color.c index cbfae774..cae9c2a8 100644 --- a/src/color.c +++ b/src/color.c @@ -3,7 +3,7 @@ * color.c * * * * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, * - * 2010, 2011, 2013, 2014 Free Software Foundation, Inc. * + * 2010, 2011, 2013, 2014, 2015 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3, or (at your option) * @@ -26,6 +26,7 @@ #include #include #include +#include #ifdef HAVE_MAGIC_H #include @@ -187,6 +188,21 @@ void color_update(void) * there was no syntax by that name, get the syntax based on the * file extension, then try the headerline, and then try magic. */ if (openfile->colorstrings == NULL) { + char *currentdir = getcwd(NULL, PATH_MAX + 1); + char *joinednames = charalloc(PATH_MAX + 1); + char *fullname = NULL; + + if (currentdir != NULL) { + /* Concatenate the current working directory with the + * specified filename, and canonicalize the result. */ + sprintf(joinednames, "%s/%s", currentdir, openfile->filename); + fullname = realpath(joinednames, NULL); + free(currentdir); + } + + if (fullname == NULL) + fullname = mallocstrcpy(fullname, openfile->filename); + for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) { @@ -211,7 +227,7 @@ void color_update(void) } /* Set colorstrings if we match the extension regex. */ - if (regexec(e->ext, openfile->filename, 0, NULL, 0) == 0) { + if (regexec(e->ext, fullname, 0, NULL, 0) == 0) { openfile->syntax = tmpsyntax; openfile->colorstrings = tmpsyntax->color; break; @@ -224,6 +240,9 @@ void color_update(void) } } + free(joinednames); + free(fullname); + /* Check the headerline if the extension didn't match anything. */ if (openfile->colorstrings == NULL) { #ifdef DEBUG