From 1cee4770ca5e09e3b56c0de0e8c77c2684542d18 Mon Sep 17 00:00:00 2001
From: "bbaetz%student.usyd.edu.au" <>
Date: Sun, 15 Dec 2002 17:23:55 +0000
Subject: Bug 158499 - Templatise XML bug output r=gerv, justdave a=justdave
---
Bugzilla/Bug.pm | 158 ++++++++++++-------------------------------------------
Bugzilla/Util.pm | 27 ++++++++--
2 files changed, 56 insertions(+), 129 deletions(-)
(limited to 'Bugzilla')
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index 7d7a1debc..251ad16e2 100755
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -32,7 +32,6 @@ use vars qw($unconfirmedstate $legal_keywords @legal_platform
@enterable_products %milestoneurl %prodmaxvotes);
use CGI::Carp qw(fatalsToBrowser);
-my %ok_field;
use Attachment;
use Bugzilla::Config;
@@ -42,18 +41,33 @@ use Bugzilla::FlagType;
use Bugzilla::User;
use Bugzilla::Util;
-for my $key (qw (bug_id alias product version rep_platform op_sys bug_status
- resolution priority bug_severity component assigned_to
- reporter bug_file_loc short_desc target_milestone
- qa_contact status_whiteboard creation_ts keywords
- delta_ts votes whoid usergroupset comment query error
- longdescs cc milestoneurl attachments dependson blocked
- cclist_accessible reporter_accessible
- isopened isunconfirmed assigned_to_name assigned_to_email
- qa_contact_name qa_contact_email reporter_name
- reporter_email flag_types num_attachment_flag_types
- show_attachment_flags use_keywords any_flags_requesteeble
- estimated_time remaining_time actual_time) ) {
+sub fields {
+ # Keep this ordering in sync with bugzilla.dtd
+ my @fields = qw(bug_id alias creation_ts short_desc delta_ts
+ reporter_accessible cclist_accessible
+ product component version rep_platform op_sys
+ bug_status resolution
+ bug_file_loc status_whiteboard keywords
+ priority bug_severity target_milestone
+ dependson blocked votes
+ reporter assigned_to qa_contact cc
+ );
+
+ if (Param('timetrackinggroup')) {
+ push @fields, qw(estimated_time remaining_time actual_time);
+ }
+
+ return @fields;
+}
+
+my %ok_field;
+foreach my $key (qw(error groups
+ longdescs milestoneurl attachments
+ isopened isunconfirmed
+ flag_types num_attachment_flag_types
+ show_attachment_flags use_keywords any_flags_requesteeble
+ ),
+ fields()) {
$ok_field{$key}++;
}
@@ -81,8 +95,6 @@ sub new {
return $self;
}
-
-
# dump info about bug into hash unless user doesn't have permission
# user_id 0 is used when person is not logged in.
#
@@ -90,10 +102,13 @@ sub initBug {
my $self = shift();
my ($bug_id, $user_id) = (@_);
+ $bug_id = trim($bug_id);
+
+ my $old_bug_id = $bug_id;
+
# If the bug ID isn't numeric, it might be an alias, so try to convert it.
$bug_id = &::BugAliasToID($bug_id) if $bug_id !~ /^[1-9][0-9]*$/;
-
- my $old_bug_id = $bug_id;
+
if ((! defined $bug_id) || (!$bug_id) || (!detaint_natural($bug_id))) {
# no bug number given or the alias didn't match a bug
$self->{'bug_id'} = $old_bug_id;
@@ -232,7 +247,7 @@ sub initBug {
my @depends = EmitDependList("blocked", "dependson", $bug_id);
if (@depends) {
$self->{'dependson'} = \@depends;
- }
+ }
my @blocked = EmitDependList("dependson", "blocked", $bug_id);
if (@blocked) {
$self->{'blocked'} = \@blocked;
@@ -327,6 +342,7 @@ sub groups {
&& ($membercontrol == CONTROLMAPMANDATORY);
push (@groups, { "bit" => $groupid,
+ "name" => $name,
"ison" => $ison,
"ingroup" => $ingroup,
"mandatory" => $ismandatory,
@@ -427,77 +443,6 @@ sub choices {
return $self->{'choices'};
}
-# given a bug hash, emit xml for it. with file header provided by caller
-#
-sub emitXML {
- ( $#_ == 0 ) || confess("invalid number of arguments");
- my $self = shift();
- my $xml;
-
-
- if (exists $self->{'error'}) {
- $xml .= "{'error'}\">\n";
- $xml .= " $self->{'bug_id'}\n";
- $xml .= "\n";
- return $xml;
- }
-
- $xml .= "\n";
-
- foreach my $field ("bug_id", "alias", "bug_status", "product",
- "priority", "version", "rep_platform", "assigned_to", "delta_ts",
- "component", "reporter", "target_milestone", "bug_severity",
- "creation_ts", "qa_contact", "op_sys", "resolution", "bug_file_loc",
- "short_desc", "keywords", "status_whiteboard") {
- if ($self->{$field}) {
- $xml .= " <$field>" . QuoteXMLChars($self->{$field}) . "$field>\n";
- }
- }
-
- foreach my $field ("dependson", "blocked", "cc") {
- if (defined $self->{$field}) {
- for (my $i=0 ; $i < @{$self->{$field}} ; $i++) {
- $xml .= " <$field>" . $self->{$field}[$i] . "$field>\n";
- }
- }
- }
-
- if (defined $self->{'longdescs'}) {
- for (my $i=0 ; $i < @{$self->{'longdescs'}} ; $i++) {
- next if ($self->{'longdescs'}[$i]->{'isprivate'}
- && Param("insidergroup")
- && !&::UserInGroup(Param("insidergroup")));
- $xml .= " \n";
- $xml .= " " . $self->{'longdescs'}[$i]->{'email'}
- . "\n";
- $xml .= " " . $self->{'longdescs'}[$i]->{'time'}
- . "\n";
- $xml .= " " . QuoteXMLChars($self->{'longdescs'}[$i]->{'body'})
- . "\n";
- $xml .= " \n";
- }
- }
-
- if (defined $self->{'attachments'}) {
- for (my $i=0 ; $i < @{$self->{'attachments'}} ; $i++) {
- next if ($self->{'attachments'}[$i]->{'isprivate'}
- && Param("insidergroup")
- && !&::UserInGroup(Param("insidergroup")));
- $xml .= " \n";
- $xml .= " " . $self->{'attachments'}[$i]->{'attachid'}
- . "\n";
- $xml .= " " . $self->{'attachments'}[$i]->{'date'} . "\n";
- $xml .= " " . QuoteXMLChars($self->{'attachments'}[$i]->{'description'}) . "\n";
- # $xml .= " " . $self->{'attachments'}[$i]->{'type'} . "\n";
- # $xml .= " " . $self->{'attachments'}[$i]->{'data'} . "\n";
- $xml .= " \n";
- }
- }
-
- $xml .= "\n";
- return $xml;
-}
-
sub EmitDependList {
my ($myfield, $targetfield, $bug_id) = (@_);
my @list;
@@ -513,41 +458,6 @@ sub EmitDependList {
return @list;
}
-sub QuoteXMLChars {
- $_[0] =~ s/&/&/g;
- $_[0] =~ s/</g;
- $_[0] =~ s/>/>/g;
- $_[0] =~ s/\'/'/g;
- $_[0] =~ s/\"/"/g;
-# $_[0] =~ s/([\x80-\xFF])/&XmlUtf8Encode(ord($1))/ge;
- return($_[0]);
-}
-
-sub XML_Header {
- my ($urlbase, $version, $maintainer, $exporter) = (@_);
-
- my $xml;
- $xml = "\n";
- $xml .= "\n";
- $xml .= "\n";
- return ($xml);
-}
-
-
-sub XML_Footer {
- return ("\n");
-}
-
sub AUTOLOAD {
use vars qw($AUTOLOAD);
my $attr = $AUTOLOAD;
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm
index efd107c0a..5aecb5ad9 100644
--- a/Bugzilla/Util.pm
+++ b/Bugzilla/Util.pm
@@ -25,15 +25,15 @@
package Bugzilla::Util;
-use Bugzilla::Config;
+use strict;
use base qw(Exporter);
@Bugzilla::Util::EXPORT = qw(is_tainted trick_taint detaint_natural
- html_quote url_quote value_quote
+ html_quote url_quote value_quote xml_quote
lsearch max min
trim format_time);
-use strict;
+use Bugzilla::Config;
# This is from the perlsec page, slightly modifed to remove a warning
# From that page:
@@ -89,6 +89,16 @@ sub value_quote {
return $var;
}
+sub xml_quote {
+ my ($var) = (@_);
+ $var =~ s/\&/\&/g;
+ $var =~ s/\</g;
+ $var =~ s/>/\>/g;
+ $var =~ s/\"/\"/g;
+ $var =~ s/\'/\'/g;
+ return $var;
+}
+
sub lsearch {
my ($list,$item) = (@_);
my $count = 0;
@@ -124,7 +134,6 @@ sub trim {
return $str;
}
-# Bug 67077
sub format_time {
my ($time) = @_;
@@ -149,7 +158,8 @@ sub format_time {
}
if (defined $year) {
- $time = "$year-$month-$day $hour:$min " . &::Param('timezone');
+ $time = "$year-$month-$day $hour:$min";
+ $time .= " " . &::Param('timezone') if &::Param('timezone');
}
return $time;
}
@@ -175,6 +185,7 @@ Bugzilla::Util - Generic utility functions for bugzilla
html_quote($var);
url_quote($var);
value_quote($var);
+ xml_quote($var);
# Functions for searching
$loc = lsearch(\@arr, $val);
@@ -252,6 +263,12 @@ Quotes characters so that they may be included as part of a url.
As well as escaping html like C, this routine converts newlines
into
, suitable for use in html attributes.
+=item C
+
+This is similar to C, except that ' is escaped to '. This
+is kept separate from html_quote partly for compatibility with previous code
+(for ') and partly for future handling of non-ASCII characters.
+
=back
=head2 Searching
--
cgit v1.2.3-24-g4f1b