nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit ec8d51bee33a3a46b2d92566bc2a5423d522b4af
parent 3739016e45145f677519c6a5c23d151f0c3c68d5
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Tue, 28 Apr 2015 19:18:38 +0000

Matching 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.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5218 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

Diffstat:
MChangeLog | 5+++++
Msrc/color.c | 23+++++++++++++++++++++--
2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,8 @@ +2015-04-28 Benno Schulenberg <bensberg@justemail.net> + * 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 <bensberg@justemail.net> * 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 @@ -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 <stdio.h> #include <string.h> #include <errno.h> +#include <unistd.h> #ifdef HAVE_MAGIC_H #include <magic.h> @@ -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