Subject: | Two problems with dir-changed paths in regex match |
Date: | Wed, 29 Aug 2007 10:59:04 -0700 |
To: | bug-SVN-Notify [...] rt.cpan.org |
From: | Wayne Davison <wdavison [...] sourceforge.net> |
The code that matches the directory prefix needs a couple fixes. Here
is the original code:
$cx ||= $_;
$cx =~ s{[/\\]?[^/\\]+$}{} until !$cx || /^$cx/;
The $_ variable holds a path that was output by dirs-changed. If that
path contains one or more regex chars (such as '+'), it will either
match inconsistently, or the regex will fail to compile. To fix this, I
added \Q and \E around the $cx variable.
The second problem is that a directory prefix could match a longer-named
directory. For instance, if $_ had the value "/some/path2" and $cw had
the value "/some/path", it would match rather than being shortened to
"/some". To fix this, I added a requirement that the end of the $cw
string must be at a slash, at a backslash, or at the end of the $_ string.
Attached is a patch that fixes both problems.
..wayne..
--- Notify.pm.old 2007-06-16 22:08:29 -0700
+++ Notify.pm 2007-08-29 10:28:11 -0700
@@ -974,7 +974,7 @@
# XXX Do we need to set utf8 here?
my $l = length;
$cx ||= $_;
- $cx =~ s{[/\\]?[^/\\]+$}{} until !$cx || /^$cx/;
+ $cx =~ s{[/\\]?[^/\\]+$}{} until !$cx || m{^\Q$cx\E(/|\\|$)};
}
}
$self->_dbpnt( qq{Context is "$cx"})