Re: [PATCH 3/7] Extract, test and enhance the logic to collapse ../foo paths.
From: Eric Wong <hidden>
Date: 2016-06-15 22:54:23
"Michael G. Schwern" [off-list ref] wrote:
From: "Michael G. Schwern" <redacted> 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.
quoted hunk ↗ jump to hunk
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...