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

[PATCH] gitweb: More detailed error messages for snapshot format

From
Jakub Narebski <jnareb@gmail.com>
Date
Jul 24, 2007, 21:00 UTC
Message-ID
<11853108372532-git-send-email-jnareb@gmail.com>

Improve error messages for snapshot format in git_snapshot: distinguish between situation where snapshots are turned off, where snapshot format ('sf') parameter is invalid, where given snapshot format does not exist in %known_snapshot_formats hash, and where gitweb was given unsupported snapshot format.

While at it, use first from all supported snapshots format as default, if no snapshot format was provided.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index fdfce31..708448c 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -4317,9 +4317,16 @@ sub git_snapshot {
 	@supported_fmts = filter_snapshot_fmts(@supported_fmts);
 
 	my $format = $cgi->param('sf');
-	unless ($format =~ m/[a-z0-9]+/
-	        && exists($known_snapshot_formats{$format})
-	        && grep($_ eq $format, @supported_fmts)) {
+	if (!@supported_fmts) {
+		die_error('403 Permission denied', "Permission denied");
+	}
+	# default to first supported snapshot format
+	$format ||= $supported_fmts[0];
+	if ($format !~ m/[a-z0-9]+/) {
+		die_error(undef, "Invalid snapshot format parameter");
+	} elsif (!exists($known_snapshot_formats{$format})) {
+		die_error(undef, "Unknown snapshot format");
+	} elsif (!grep($_ eq $format, @supported_fmts)) {
 		die_error(undef, "Unsupported snapshot format");
 	}
 
-- 
1.5.2.4
Next: Matt McCutchen
Message 1 of 3 in “gitweb: More detailed error messages for snapshot format”
  1. gitweb: More detailed error messages for snapshot formatJakub Narebski, Jul 24, 2007
  2. Matt McCutchenJul 24, 2007
  3. gitweb: More detailed error messages for snapshot formatJakub Narebski, Jul 24, 2007

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.