Skip to content

Commit 8db49a7

Browse files
Oblomovgitster
authored andcommitted
gitweb: generate parent..current URLs
If use_pathinfo is enabled, href now creates links that contain paths in the form $project/$action/oldhash:/oldname..newhash:/newname for actions that use hash_parent etc. If any of the filename contains two consecutive dots, it's kept as a CGI parameter since the resulting path would otherwise be ambiguous. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Acked-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b0be383 commit 8db49a7

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

gitweb/gitweb.perl

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ (%)
766766
# try to put as many parameters as possible in PATH_INFO:
767767
# - project name
768768
# - action
769+
# - hash_parent or hash_parent_base:/file_parent
769770
# - hash or hash_base:/filename
770771

771772
# When the script is the root DirectoryIndex for the domain,
@@ -785,17 +786,36 @@ (%)
785786
delete $params{'action'};
786787
}
787788

788-
# Finally, we put either hash_base:/file_name or hash
789+
# Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
790+
# stripping nonexistent or useless pieces
791+
$href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
792+
|| $params{'hash_parent'} || $params{'hash'});
789793
if (defined $params{'hash_base'}) {
790-
$href .= "/".esc_url($params{'hash_base'});
791-
if (defined $params{'file_name'}) {
794+
if (defined $params{'hash_parent_base'}) {
795+
$href .= esc_url($params{'hash_parent_base'});
796+
# skip the file_parent if it's the same as the file_name
797+
delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
798+
if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
799+
$href .= ":/".esc_url($params{'file_parent'});
800+
delete $params{'file_parent'};
801+
}
802+
$href .= "..";
803+
delete $params{'hash_parent'};
804+
delete $params{'hash_parent_base'};
805+
} elsif (defined $params{'hash_parent'}) {
806+
$href .= esc_url($params{'hash_parent'}). "..";
807+
delete $params{'hash_parent'};
808+
}
809+
810+
$href .= esc_url($params{'hash_base'});
811+
if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
792812
$href .= ":/".esc_url($params{'file_name'});
793813
delete $params{'file_name'};
794814
}
795815
delete $params{'hash'};
796816
delete $params{'hash_base'};
797817
} elsif (defined $params{'hash'}) {
798-
$href .= "/".esc_url($params{'hash'});
818+
$href .= esc_url($params{'hash'});
799819
delete $params{'hash'};
800820
}
801821
}

0 commit comments

Comments
 (0)