6 Oct 21:18
[PATCH] gitweb: Convert Content-Disposition filenames into qtext
Luben Tuikov <ltuikov <at> yahoo.com>
2006-10-06 19:18:01 GMT
2006-10-06 19:18:01 GMT
Convert a string (e.g. a filename) into qtext as defined in RFC 822, from RFC 2183. To be used by Content-Disposition. Signed-off-by: Luben Tuikov <ltuikov <at> yahoo.com> --- gitweb/gitweb.perl | 18 ++++++++++++++---- 1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index f848648..a35d02c 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -520,6 +520,16 @@ sub esc_html {
return $str;
}
+# Convert a string (e.g. a filename) into qtext as defined
+# in RFC 822, from RFC 2183. To be used by Content-Disposition.
+sub to_qtext {
+ my $str = shift;
+ $str =~ s/\\/\\\\/g;
+ $str =~ s/\"/\\\"/g;
+ $str =~ s/\r/\\r/g;
+ return $str;
+}
+
# git may return quoted and escaped filenames
sub unquote {
my $str = shift;
@@ -2742,7 +2752,7 @@ sub git_blob_plain {
print $cgi->header(
-type => "$type",
-expires=>$expires,
- -content_disposition => 'inline; filename="' . "$save_as" . '"');
+ -content_disposition => 'inline; filename="' . to_qtext("$save_as") . '"');
undef $/;
binmode STDOUT, ':raw';
print <$fd>;
@@ -2917,7 +2927,7 @@ sub git_snapshot {
print $cgi->header(
-type => 'application/x-tar',
-content_encoding => $ctype,
- -content_disposition => 'inline; filename="' . "$filename" . '"',
+ -content_disposition => 'inline; filename="' . to_qtext("$filename") . '"',
-status => '200 OK');
my $git = git_cmd_str();
@@ -3224,7 +3234,7 @@ sub git_blobdiff {
-type => 'text/plain',
-charset => 'utf-8',
-expires => $expires,
- -content_disposition => 'inline; filename="' . "$file_name" . '.patch"');
+ -content_disposition => 'inline; filename="' . to_qtext("$file_name") . '.patch"');
print "X-Git-Url: " . $cgi->self_url() . "\n\n";
@@ -3327,7 +3337,7 @@ sub git_commitdiff {
-type => 'text/plain',
-charset => 'utf-8',
-expires => $expires,
- -content_disposition => 'inline; filename="' . "$filename" . '"');
+ -content_disposition => 'inline; filename="' . to_qtext("$filename") . '"');
my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
print <<TEXT;
From: $co{'author'}
--
--
1.4.2.3.g0954
RSS Feed