git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] gitweb: use correct mime type even if filename has multiple dots.

From
Martin Waitz <tali@admingilde.org>
Date
Sep 16, 2006, 21:09 UTC
Message-ID
<20060916210933.GX17042@admingilde.org>

Match the last part of the filename agains the extention from the mime database instead of insisting that it starts at the first dot.

Signed-off-by: Martin Waitz <tali@admingilde.org>
---
 gitweb/gitweb.perl |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index ee561c6..7501251 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1106,7 +1106,6 @@ sub mimetype_guess_file {
 	my $mimemap = shift;
 	-r $mimemap or return undef;
 
-	my %mimemap;
 	open(MIME, $mimemap) or return undef;
 	while (<MIME>) {
 		next if m/^#/; # skip comments
@@ -1114,14 +1113,16 @@ sub mimetype_guess_file {
 		if (defined $exts) {
 			my @exts = split(/\s+/, $exts);
 			foreach my $ext (@exts) {
-				$mimemap{$ext} = $mime;
+				if ($filename =~ /\.$ext$/) {
+					close(MIME);
+					return $mime;
+				}
 			}
 		}
 	}
 	close(MIME);
 
-	$filename =~ /\.(.*?)$/;
-	return $mimemap{$1};
+	return undef;
 }
 
 sub mimetype_guess {
-- 
1.4.2.gb8b6b

-- 
Martin Waitz
Next: Jakub Narebski
Message 1 of 10 in “gitweb: use correct mime type even if filename has multiple dots.”
  1. gitweb: use correct mime type even if filename has multiple dots.Martin Waitz, Sep 16, 2006
  2. Jakub NarebskiSep 16, 2006
  3. Martin WaitzSep 17, 2006
  4. Jakub NarebskiSep 17, 2006
  5. Martin WaitzSep 19, 2006
  6. gitweb: Fix mimetype_guess_file for files with multiple extensionsJakub Narebski, Sep 19, 2006
  7. Junio C HamanoSep 17, 2006
  8. Jakub NarebskiSep 17, 2006
  9. Junio C HamanoSep 17, 2006
  10. Martin WaitzSep 19, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.