Re: [PATCH 3/7] Extract, test and enhance the logic to collapse ../foo paths.
- From
Michael G Schwern <schwern@pobox.com>
- Date
- Jul 30, 2012, 20:46 UTC
- Message-ID
- <5016F2A5.1090102@pobox.com>
- In-Reply-To
- <20120730195108.GA20137@dcvr.yhbt.net>
On 2012.7.30 12:51 PM, Eric Wong wrote:
Show 7 quoted lines
>> 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".
Yeah. I figured the tests covered that.
Show 11 quoted lines
>> +# 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.Good catch. Woo unit tests! :) You could add them as TODO tests.
A more accurate way to do it would be to split the path, collapse using the resulting list, and rejoin it.
> [1] - I doubt anybody uses paths like these, though...
Not for an svnroot or branch name, no.
-- Hating the web since 1994.