bugzilla validation



Good day,

I tried to make sure I had all the latest patches, so hopefully I'm not
recreating someone else's fix.

I was getting tired of every numerical clue triggering a slew of
bugzilla reports for bug ##### with '???' for all the fields so I added
a check to the xml returned by bugzilla. 

I noticed that the <bug> tag had an attribute 'error' such that:

<bug error="NotFound">
...
</bug>

indicated that you searched on a bogus value.

I added a function "IsValidBug" that takes the XML and tries to find the
"error" tag. Right now it returns false anytime there is an "error"
attribute, or it can't find the "/bugzilla/bug" tag. If there are
"error" tags that appear even when a legit bug is found, we'll have to
modify this function to handle them.

This is my first patch so feel free to criticize style or approach :)

-D
Index: backends/backend-bugzilla.cs
===================================================================
RCS file: /cvs/gnome/dashboard/backends/backend-bugzilla.cs,v
retrieving revision 1.14
diff -u -r1.14 backend-bugzilla.cs
--- backends/backend-bugzilla.cs	24 Dec 2003 19:10:20 -0000	1.14
+++ backends/backend-bugzilla.cs	3 Jan 2004 23:25:36 -0000
@@ -104,7 +104,12 @@
 		{
 			string bug_num, product, summary, owner, status;
 
-			try {
+			// see if the bug was even found. If there wasn't a bug, there will be
+			// an error attribute on the /bug element that says NotFound if one didn't exist.
+			if(!IsValidBug(xml))
+				return null;
+				
+			try { 
 				bug_num = this.GetXmlText (xml, "//bug_id");
 				product = this.GetXmlText (xml, "//product");
 				summary = this.GetXmlText (xml, "//short_desc");
@@ -161,6 +166,36 @@
 
 			return node.InnerText;
 		}
+
+		// Determines if the bug is valid or if we searched on some number
+		// that we thought might have been a bugzilla number.
+		// Rather than return all '???' let's just ignore them
+		private bool IsValidBug(XmlDocument xml)
+		{
+			try{			
+				XmlNode node;
+				node = xml.SelectSingleNode("/bugzilla/bug");
+              	
+				// if we can't find the "bug" element, then it's not valid
+				if(node == null)
+					return false;				
+
+				XmlNode attrib;
+				attrib = node.Attributes.GetNamedItem("error");
+
+				// if there's no error attribute, it's legit
+				// Note: I don't know what possible values for "error" are.
+				// I know if the bug isn't there, you will get 'NotFound' so I'm assuming that any
+				// error attribute is bad
+				
+				if(attrib == null)
+					return true;					
+			}catch{
+				// on error, assume it's not a bug:
+				return false;
+			}
+			return false;
+		}                                                                      
 	}
 
 } // namespace Dashboard


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]