summaryrefslogtreecommitdiffstats
path: root/globals.pl
diff options
context:
space:
mode:
authorbbaetz%acm.org <>2003-03-22 10:17:00 +0100
committerbbaetz%acm.org <>2003-03-22 10:17:00 +0100
commit3f1f4e57809b2e3f42e637a86646e806470faec5 (patch)
tree60a0b2b106888a7fa8f6bc1085fa1a9d1168102d /globals.pl
parent78db8be8ca8f3de2169981a2ead269fd12395089 (diff)
downloadbugzilla-3f1f4e57809b2e3f42e637a86646e806470faec5.tar.gz
bugzilla-3f1f4e57809b2e3f42e637a86646e806470faec5.tar.xz
Bug 195695 - Requesting a non-existant format results in an Internal Error
r=gerv, a=myk
Diffstat (limited to 'globals.pl')
-rw-r--r--globals.pl20
1 files changed, 19 insertions, 1 deletions
diff --git a/globals.pl b/globals.pl
index 812fdff15..ae656d9ec 100644
--- a/globals.pl
+++ b/globals.pl
@@ -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} ,
};
}