"Michael G. Schwern" <schw...@pobox.com> wrote:
> From: "Michael G. Schwern" <schw...@pobox.com>
> 
> 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...
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to