From: Eric Wong Date: Mon, 30 Jul 2012 19:51:08 GMT Subject: Re: [PATCH 3/7] Extract, test and enhance the logic to collapse ../foo paths. Message-ID: <20120730195108.GA20137@dcvr.yhbt.net> In-Reply-To: <1343468312-72024-4-git-send-email-schwern@pobox.com> "Michael G. Schwern" wrote: > From: "Michael G. Schwern" > > The SVN API functions will not accept ../foo but their canonicalization > functions will not collapse it. So we'll have to do it ourselves. > > _collapse_dotdot() works better than the existing regex did. I don't dispute it's better, but it's worth explaining in the commit message to reviewers why something is "better". > This will be used shortly when canonicalize_path() starts using the > SVN API. > --- > +# Turn foo/../bar into bar > +sub _collapse_dotdot { > + my $path = shift; > + > + 1 while $path =~ s{/[^/]+/+\.\.}{}; > + 1 while $path =~ s{[^/]+/+\.\./}{}; > + 1 while $path =~ s{[^/]+/+\.\.}{}; This is a bug that's gone unnoticed[1] for over 5 years now, but I've just noticed this doesn' handle "foo/..bar" or "foo/...bar" cases correctly. > sub canonicalize_path { > my ($path) = @_; > my $dot_slash_added = 0; > @@ -83,7 +95,7 @@ sub canonicalize_path { > # good reason), so let's do this manually. > $path =~ s#/+#/#g; > $path =~ s#/\.(?:/|$)#/#g; > - $path =~ s#/[^/]+/\.\.##g; > + $path = _collapse_dotdot($path); [1] - I doubt anybody uses paths like these, though...