git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: Junio C Hamano <junkio@cox.net>, git@vger.kernel.org
Cc: Martin Koegler <mkoegler@auto.tuwien.ac.at>
Subject: Re: [PATCH] gitweb: Support comparing blobs (files) with different names
Date: Tue, 3 Apr 2007 16:57:24 +0200	[thread overview]
Message-ID: <200704031657.25698.jnareb@gmail.com> (raw)
In-Reply-To: <7vmz1t6oe2.fsf@assigned-by-dhcp.cox.net>

On Sun, Apr 1, 2007, Junio C Hamano wrote:
> Jakub Narebski <jnareb@gmail.com> writes:
> 
>>> First is not escaped filename in HTTP header. There was some discussion
>>> about this, and even patch by Luben Tuikov which added to_qtext 
>>> subroutine to deal with escaping in HTTP (which has diferent rules than
>>> escaping in HTML, or in HTML attributes)
>>>  * gitweb: using quotemeta
>>>    http://thread.gmane.org/gmane.comp.version-control.git/28050/
>>>  * [PATCH] gitweb: Convert Content-Disposition filenames into qtext
>>>    http://thread.gmane.org/gmane.comp.version-control.git/28437
>>> But the patch was newer accepted; either lost in the noise, or in lack
>>> of summary to the discussion.
>>
>> Junio, do you remember by chance why this patch was dropped?
> 
> No, but I suspect that was because the noisiness of the thread
> around them suggested they were not ready to be applied.  I do
> not remember if people submitted the patch and commented on
> reached a consensus.

Probably not. Here is alternative proposal. It does not implement
  RFC2184: MIME Parameter Value and Encoded Word Extensions
but I'm not sure if 1) it is needed for _HTTP_ Content-Disposition
header filename, 2) all browsers implement it.

By the way, $str =~ s/[\n\r]/_/g; line (as per Junio Hamano and Petr
Baudis suggestion) is needed not only for buggy browsers, but also for
buggy CGI implementation:

  $ perl -wle \
  'use CGI; \
   our $cgi = new CGI; \
   print $cgi->header(-content_disposition => "inline; filename=\"file\nname\"");'

generates (for CGI version 3.10)

  Content-disposition="inline; filename=&quot;file
  name&quot;"

which is a bit strange. Single LF (not CRLF pair) does not need to be
quoted in the header, as per RFC822.

-- >8 --
# Generate value of Content-Disposition header field, with "inline"
# disposition type, for a given filename parameter
# Usage: $cgi->header( [...],
#          -content_disposition => content_disposition($filename))
# References: RFC 2183, RFC 822 and RFC 2045
sub content_disposition {
	my $filename = shift;

	#RFC2183: The Content-Disposition Header Field
	# parameter value containing only non-`tspecials' characters [RFC 2045]
	# SHOULD be represented as a single `token'.
	#RFC2045: MIME Part One: Format of Internet Message Bodies
	# token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
	#             or tspecials>
	if ($filename =~ m/[[:space:][:cntrl:]()<>@,;:\\"\/\[\]?=]/) {
		#RFC2183: The Content-Disposition Header Field
		# parameter value containing only ASCII characters, but including
		# `tspecials' characters, SHOULD be represented as `quoted-string'.

		# It not worth potential problems to try to carry newlines (and such)
		# in the header; it is just _suggested_ filename
		$filename =~ s/[[:cntrl:]\n\r]/_/g;

		#RFC822: Standard for the Format of ARPA Internet Text Messages
		# quoting is REQUIRED for CR and "\" and for the character(s) that
		# delimit the token (e.g., "(" and ")" for a comment).  However,
		# quoting is PERMITTED for any character.
		$filename =~ s/([\\"\r])/\\$1/g;
		$filename = '"' . $filename . '"';
	}
	return "inline; filename=$filename";
}
-- >8 --
P.S. We could probably always quote filename parameter, even if it
is not needed ("SHOULD be represented as a single `token'" part).

P.P.S. Here is an example of RFC2184 encoded header:

   Content-Type: application/x-stuff
    title*1*=us-ascii'en'This%20is%20even%20more%20
    title*2*=%2A%2A%2Afun%2A%2A%2A%20
    title*3="isn't it!"

-- 
Jakub Narebski
Poland

  parent reply	other threads:[~2007-04-03 16:23 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-25 20:34 [PATCH] gitweb: show no difference message Martin Koegler
2007-03-25 20:34 ` [PATCH] gitweb: Support comparing blobs with different names Martin Koegler
2007-03-25 20:34   ` [PATCH] gitweb: link base commit (hpb) to blobdiff output Martin Koegler
2007-03-25 20:34     ` [PATCH] gitweb: support filename prefix in git_patchset_body Martin Koegler
2007-03-25 20:34       ` [PATCH] gitweb: support filename prefix in git_difftree_body Martin Koegler
2007-03-25 20:34         ` [PATCH] gitweb: Add treediff Martin Koegler
2007-03-26 17:12           ` Jakub Narebski
2007-03-26 21:05             ` Martin Koegler
2007-03-27  1:15               ` Jakub Narebski
2007-03-26 17:12       ` [PATCH] gitweb: support filename prefix in git_patchset_body Jakub Narebski
2007-03-26 20:55         ` Martin Koegler
2007-03-27  1:07           ` Jakub Narebski
2007-03-26 17:12   ` [PATCH] gitweb: Support comparing blobs (files) with different names Jakub Narebski
2007-03-26 20:41     ` Martin Koegler
2007-03-27  0:56       ` Jakub Narebski
2007-03-27 19:56         ` Martin Koegler
2007-03-27 23:58           ` Jakub Narebski
2007-03-28 21:03             ` Martin Koegler
2007-03-30  8:48               ` Jakub Narebski
2007-03-30 23:55               ` Jakub Narebski
2007-03-31  9:18                 ` Martin Koegler
2007-03-31 16:16                 ` Jakub Narebski
     [not found]                   ` <7vmz1t6oe2.fsf@assigned-by-dhcp.cox.net>
2007-04-03 14:57                     ` Jakub Narebski [this message]
2007-04-04 21:27                       ` Jakub Narebski
2007-04-05 10:38                         ` Junio C Hamano
2007-03-31 14:52               ` [PATCH] gitweb: Fix bug in "blobdiff" view for split (e.g. file to symlink) patches Jakub Narebski
2007-03-26 17:11 ` [PATCH] gitweb: show no difference message Jakub Narebski
2007-03-26 21:01   ` Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200704031657.25698.jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=mkoegler@auto.tuwien.ac.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).