]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 195695 - Requesting a non-existant format results in an Internal Error
authorbbaetz%acm.org <>
Sat, 22 Mar 2003 09:17:00 +0000 (09:17 +0000)
committerbbaetz%acm.org <>
Sat, 22 Mar 2003 09:17:00 +0000 (09:17 +0000)
r=gerv, a=myk

globals.pl
template/en/default/global/user-error.html.tmpl

index 812fdff15006422dfe5b6f99a76388d9039c622d..ae656d9ec96972671e60257a1138d4886cb0b1c6 100644 (file)
@@ -1490,6 +1490,7 @@ sub FormatTimeUnit {
 # Constructs a format object from URL parameters. You most commonly call it 
 # like this:
 # my $format = GetFormat("foo/bar", $::FORM{'format'}, $::FORM{'ctype'});
+
 sub GetFormat {
     my ($template, $format, $ctype) = @_;
 
@@ -1505,11 +1506,28 @@ sub GetFormat {
     $template .= ($format ? "-$format" : "");
     $template .= ".$ctype.tmpl";
 
+    # Now check that the template actually exists. We only want to check
+    # if the template exists; any other errors (eg parse errors) will
+    # end up being detected laer.
+    eval {
+        Bugzilla->template->context->template($template);
+    };
+    # This parsing may seem fragile, but its OK:
+    # http://lists.template-toolkit.org/pipermail/templates/2003-March/004370.html
+    # Even if it is wrong, any sort of error is going to cause a failure
+    # eventually, so the only issue would be an incorrect error message
+    if ($@ && $@->info =~ /: not found$/) {
+        ThrowUserError("format_not_found", { 'format' => $format,
+                                             'ctype' => $ctype,
+                                           });
+    }
+
+    # Else, just return the info
     return
     {
         'template'    => $template ,
         'extension'   => $ctype ,
-        'ctype' => $::contenttypes->{$ctype} || "text/plain" ,
+        'ctype' => $::contenttypes->{$ctype} ,
     };
 }
 
index dfb8af9fabc5a8a8b90921899204bf1ffc655fe5..89f8cb7f30507e2a6f02449a970be1b632a4711b 100644 (file)
   [% ELSIF error == "flag_type_name_invalid" %]
     [% title = "Flag Type Name Invalid" %]
     The name <em>[% name FILTER html %]</em> must be 1-50 characters long.
+
+  [% ELSIF error == "format_not_found" %]
+    [% title = "Format Not Found" %]
+    The requested format <em>[% format FILTER html %]</em> does not exist with
+    a content type of <em>[% ctype FILTER html %]</em>.
     
   [% ELSIF error == "flag_type_sortkey_invalid" %]
     [% title = "Flag Type Sort Key Invalid" %]