From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: Jakub Narebski <jnareb@gmail.com>
Subject: [RFC/PATCH] gitweb: Try to sanitize mimetype for 'blob_plain' view
Date: Mon, 19 Nov 2007 15:54:14 +0100 [thread overview]
Message-ID: <1195484054-18164-1-git-send-email-jnareb@gmail.com> (raw)
Use 'text/plain' for files which are text and can be viewed in a
browser, and are not among a few 'text/*' mimetypes universally
recognized by web browsers. This means files with 'text/*' which are
not text/html, text/css, text/sgml or text/xml, and files with
'application/x-*' mimetype which are nevertheless text: javascript,
shell, Perl, Tcl, (La)TeX,...
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Tired of my web browser (Mozilla) asking me what I want to do with
shell script, Perl script or LaTeX document when using 'blob_plain'
(raw) view, because of declaration in mimetypes file I have added
mimetype sanitizing to gitweb.
It is an RFC partially because list of mimetypes is a bit
arbitrary. Additionally I guess that the mimetype sanitizing should be
separated into subroutine.
But most of all beause proper solution is to create mimetype file for
use by gitweb.
gitweb/gitweb.perl | 23 ++++++++++++++++++++++-
1 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 491a3f4..1cfe293 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2366,7 +2366,28 @@ sub blob_mimetype {
if ($filename) {
my $mime = mimetype_guess($filename);
- $mime and return $mime;
+
+ if ($mime) {
+ # try to sanitize mimetype
+
+ # return text/plain on unknown text/* mimetype
+ if ($mime =~ m!^text/! &&
+ $mime !~ m!^text/(?:html|css|sgml|xml)$!) {
+ return 'text/plain' .
+ ($default_text_plain_charset ?
+ '; charset='.$default_text_plain_charset : '');
+ }
+ # return text/plain for known programming languages and like
+ if ($mime =~ m!^application/x-(?:
+ javascript|csshell|shell|csh|perl|
+ sh|shar|tcl|latex|tex|texinfo)!x) {
+ return 'text/plain' .
+ ($default_text_plain_charset ?
+ '; charset='.$default_text_plain_charset : '');
+ }
+ # otherwise return mimetype found in mimetypes file(s)
+ return $mime;
+ }
}
# just in case
--
1.5.3.5
next reply other threads:[~2007-11-19 14:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-19 14:54 Jakub Narebski [this message]
2007-11-20 8:07 ` [RFC/PATCH] gitweb: Try to sanitize mimetype for 'blob_plain' view Junio C Hamano
[not found] ` <4BAE81C8-EFF3-473D-B243-B7D0F66F131B@wincent.com>
2007-11-20 10:58 ` 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=1195484054-18164-1-git-send-email-jnareb@gmail.com \
--to=jnareb@gmail.com \
--cc=git@vger.kernel.org \
/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).