From a97964688b73d0a3237c798dce3fb064ff29ff11 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 17 Apr 2010 19:05:40 -0400 Subject: unfinished file_prune revamp Many calls to file_prune were incorrectly calling it with 2 parameters. In cases where the filename being checked is relative to the srcdir, that is not needed. Made absolute filenames be pruned. (This won't work for the 2 parameter call style.) --- t/file_pruned.t | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 't/file_pruned.t') diff --git a/t/file_pruned.t b/t/file_pruned.t index f9c1c257e..4335ed917 100755 --- a/t/file_pruned.t +++ b/t/file_pruned.t @@ -1,41 +1,75 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 27; +use Test::More tests => 54; BEGIN { use_ok("IkiWiki"); } %config=IkiWiki::defaultconfig(); ok(IkiWiki::file_pruned("src/.htaccess", "src")); +ok(IkiWiki::file_pruned(".htaccess")); ok(IkiWiki::file_pruned("src/.ikiwiki/", "src")); +ok(IkiWiki::file_pruned(".ikiwiki/")); ok(IkiWiki::file_pruned("src/.ikiwiki/index", "src")); +ok(IkiWiki::file_pruned(".ikiwiki/index")); ok(IkiWiki::file_pruned("src/CVS/foo", "src")); +ok(IkiWiki::file_pruned("CVS/foo")); ok(IkiWiki::file_pruned("src/subdir/CVS/foo", "src")); +ok(IkiWiki::file_pruned("subdir/CVS/foo")); ok(IkiWiki::file_pruned("src/.svn", "src")); +ok(IkiWiki::file_pruned(".svn")); ok(IkiWiki::file_pruned("src/subdir/.svn", "src")); +ok(IkiWiki::file_pruned("subdir/.svn")); ok(IkiWiki::file_pruned("src/subdir/.svn/foo", "src")); +ok(IkiWiki::file_pruned("subdir/.svn/foo")); ok(IkiWiki::file_pruned("src/.git", "src")); +ok(IkiWiki::file_pruned(".git")); ok(IkiWiki::file_pruned("src/subdir/.git", "src")); +ok(IkiWiki::file_pruned("subdir/.git")); ok(IkiWiki::file_pruned("src/subdir/.git/foo", "src")); +ok(IkiWiki::file_pruned("subdir/.git/foo")); ok(! IkiWiki::file_pruned("src/svn/fo", "src")); +ok(! IkiWiki::file_pruned("svn/fo")); ok(! IkiWiki::file_pruned("src/git", "src")); +ok(! IkiWiki::file_pruned("git")); ok(! IkiWiki::file_pruned("src/index.mdwn", "src")); +ok(! IkiWiki::file_pruned("index.mdwn")); ok(! IkiWiki::file_pruned("src/index.", "src")); +ok(! IkiWiki::file_pruned("index.")); # these are ok because while the filename starts with ".", the canonpathed # version does not ok(! IkiWiki::file_pruned("src/.", "src")); ok(! IkiWiki::file_pruned("src/./", "src")); +# OTOH, without a srcdir, no canonpath, so they're not allowed. +ok(IkiWiki::file_pruned(".")); +ok(IkiWiki::file_pruned("./")); + +# Without a srcdir, absolute filenames are not allowed. +ok(IkiWiki::file_pruned("/etc/passwd")); +ok(IkiWiki::file_pruned("//etc/passwd")); +ok(IkiWiki::file_pruned("/")); +ok(IkiWiki::file_pruned("//")); +ok(IkiWiki::file_pruned("///")); + ok(IkiWiki::file_pruned("src/..", "src")); +ok(IkiWiki::file_pruned("..")); ok(IkiWiki::file_pruned("src/../", "src")); +ok(IkiWiki::file_pruned("../")); ok(IkiWiki::file_pruned("src/../", "src")); +ok(IkiWiki::file_pruned("../")); +# This is perhaps counterintuitive. ok(! IkiWiki::file_pruned("src", "src")); + +# Dots, etc, in the srcdir are ok. ok(! IkiWiki::file_pruned("/.foo/src", "/.foo/src")); ok(IkiWiki::file_pruned("/.foo/src/.foo/src", "/.foo/src")); ok(! IkiWiki::file_pruned("/.foo/src/index.mdwn", "/.foo/src/index.mdwn")); -ok(IkiWiki::file_pruned("x/y/foo.dpkg-tmp", "src")); -ok(IkiWiki::file_pruned("x/y/foo.ikiwiki-new", "src")); +ok(IkiWiki::file_pruned("src/y/foo.dpkg-tmp", "src")); +ok(IkiWiki::file_pruned("y/foo.dpkg-tmp")); +ok(IkiWiki::file_pruned("src/y/foo.ikiwiki-new", "src")); +ok(IkiWiki::file_pruned("y/foo.ikiwiki-new")); -- cgit v1.2.3 From cff3937b681a6c2505eb52b43b2e3e7086f99c45 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 20 Apr 2010 14:08:29 -0400 Subject: remove 2 argument form of file_pruned --- IkiWiki.pm | 9 +-------- t/file_pruned.t | 39 ++------------------------------------- 2 files changed, 3 insertions(+), 45 deletions(-) (limited to 't/file_pruned.t') diff --git a/IkiWiki.pm b/IkiWiki.pm index a5f83ac7a..6d3b6c606 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1843,15 +1843,8 @@ sub deptype (@) { } my $file_prune_regexp; -sub file_pruned ($;$) { +sub file_pruned ($) { my $file=shift; - if (@_) { - require File::Spec; - $file=File::Spec->canonpath($file); - my $base=File::Spec->canonpath(shift); - return if $file eq $base; - $file =~ s#^\Q$base\E/+##; - } if (defined $config{include} && length $config{include}) { return 0 if $file =~ m/$config{include}/; diff --git a/t/file_pruned.t b/t/file_pruned.t index 4335ed917..34f366610 100755 --- a/t/file_pruned.t +++ b/t/file_pruned.t @@ -1,52 +1,31 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 54; +use Test::More tests => 27; BEGIN { use_ok("IkiWiki"); } %config=IkiWiki::defaultconfig(); -ok(IkiWiki::file_pruned("src/.htaccess", "src")); ok(IkiWiki::file_pruned(".htaccess")); -ok(IkiWiki::file_pruned("src/.ikiwiki/", "src")); ok(IkiWiki::file_pruned(".ikiwiki/")); -ok(IkiWiki::file_pruned("src/.ikiwiki/index", "src")); ok(IkiWiki::file_pruned(".ikiwiki/index")); -ok(IkiWiki::file_pruned("src/CVS/foo", "src")); ok(IkiWiki::file_pruned("CVS/foo")); -ok(IkiWiki::file_pruned("src/subdir/CVS/foo", "src")); ok(IkiWiki::file_pruned("subdir/CVS/foo")); -ok(IkiWiki::file_pruned("src/.svn", "src")); ok(IkiWiki::file_pruned(".svn")); -ok(IkiWiki::file_pruned("src/subdir/.svn", "src")); ok(IkiWiki::file_pruned("subdir/.svn")); -ok(IkiWiki::file_pruned("src/subdir/.svn/foo", "src")); ok(IkiWiki::file_pruned("subdir/.svn/foo")); -ok(IkiWiki::file_pruned("src/.git", "src")); ok(IkiWiki::file_pruned(".git")); -ok(IkiWiki::file_pruned("src/subdir/.git", "src")); ok(IkiWiki::file_pruned("subdir/.git")); -ok(IkiWiki::file_pruned("src/subdir/.git/foo", "src")); ok(IkiWiki::file_pruned("subdir/.git/foo")); -ok(! IkiWiki::file_pruned("src/svn/fo", "src")); ok(! IkiWiki::file_pruned("svn/fo")); -ok(! IkiWiki::file_pruned("src/git", "src")); ok(! IkiWiki::file_pruned("git")); -ok(! IkiWiki::file_pruned("src/index.mdwn", "src")); ok(! IkiWiki::file_pruned("index.mdwn")); -ok(! IkiWiki::file_pruned("src/index.", "src")); ok(! IkiWiki::file_pruned("index.")); - -# these are ok because while the filename starts with ".", the canonpathed -# version does not -ok(! IkiWiki::file_pruned("src/.", "src")); -ok(! IkiWiki::file_pruned("src/./", "src")); -# OTOH, without a srcdir, no canonpath, so they're not allowed. ok(IkiWiki::file_pruned(".")); ok(IkiWiki::file_pruned("./")); -# Without a srcdir, absolute filenames are not allowed. +# absolute filenames are not allowed. ok(IkiWiki::file_pruned("/etc/passwd")); ok(IkiWiki::file_pruned("//etc/passwd")); ok(IkiWiki::file_pruned("/")); @@ -54,22 +33,8 @@ ok(IkiWiki::file_pruned("//")); ok(IkiWiki::file_pruned("///")); -ok(IkiWiki::file_pruned("src/..", "src")); ok(IkiWiki::file_pruned("..")); -ok(IkiWiki::file_pruned("src/../", "src")); -ok(IkiWiki::file_pruned("../")); -ok(IkiWiki::file_pruned("src/../", "src")); ok(IkiWiki::file_pruned("../")); -# This is perhaps counterintuitive. -ok(! IkiWiki::file_pruned("src", "src")); - -# Dots, etc, in the srcdir are ok. -ok(! IkiWiki::file_pruned("/.foo/src", "/.foo/src")); -ok(IkiWiki::file_pruned("/.foo/src/.foo/src", "/.foo/src")); -ok(! IkiWiki::file_pruned("/.foo/src/index.mdwn", "/.foo/src/index.mdwn")); - -ok(IkiWiki::file_pruned("src/y/foo.dpkg-tmp", "src")); ok(IkiWiki::file_pruned("y/foo.dpkg-tmp")); -ok(IkiWiki::file_pruned("src/y/foo.ikiwiki-new", "src")); ok(IkiWiki::file_pruned("y/foo.ikiwiki-new")); -- cgit v1.2.3