Bug 882670 - Part 4: The search term should be trim()ed after truncation; r=RyanVM
authorEd Morley <emorley@mozilla.com>
Sun, 16 Jun 2013 15:55:03 +0100
changeset 1235 612c22f85fd0788c6152978b0b19a74655db2cb5
parent 1234 cbfbdfa6833cc68f440c21ff6c04941fae8f35b0
child 1236 bcd877b5c15182373fc2d858dca012e8bc6b7332
push id666
push useremorley@mozilla.com
push dateWed, 26 Jun 2013 21:32:24 +0000
reviewersRyanVM
bugs882670
Bug 882670 - Part 4: The search term should be trim()ed after truncation; r=RyanVM If the search term is longer than 200 characters we truncate it, since bug summaries can only hold 255 characters - and we need to leave room for the "Intermittent ..." and alternative test names etc. This truncation can leave whitespace at the end of the search term, so we should trim() afterwards.
php/inc/AnnotatedSummaryGenerator.php
--- a/php/inc/AnnotatedSummaryGenerator.php
+++ b/php/inc/AnnotatedSummaryGenerator.php
@@ -130,33 +130,32 @@ class AnnotatedSummaryGenerator implemen
     'automation.py',
     'remoteautomation.py',
     'Shutdown',
     'Main app process exited normally',
     'leakcheck'
   );
 
   protected function getBugsForFailure($searchTerm) {
-    $searchTerm = trim($searchTerm);
     // Don't search for things that will return too many (or irrelevant) results
-    if (strlen($searchTerm) < 5) {
+    if (strlen(trim($searchTerm)) < 5) {
       Debug::output('Not fetching bugs for "'.$searchTerm.'" - string too short');
       return array();
     }
     if (in_array($searchTerm, self::$blacklist)) {
       Debug::output('Not fetching bugs for "'.$searchTerm.'" - matches ignore list');
       return array();
     }
 
     // Bugzilla's max summary length is 256 characters, so once "Intermittent "
     // and platform/suite information is prefixed, it often only leaves ~200
     // characters for the failure, so anything more will be truncated in the summary.
     // We limit the length here to (a) prevent crazy length bzapi requests, and (b)
     // in the hope that we might still match the truncated failure in the summary.
-    $searchTerm = substr($searchTerm, 0, 200);
+    $searchTerm = trim(substr($searchTerm, 0, 200));
 
     global $db;
     $engine = new Services_JSON();
 
     $regenerate = isset($_GET['regenerate']) && $_GET['regenerate'] == '1';
     if ($regenerate) {
       Debug::output('Removing cached bug suggestions for "'.$searchTerm.'"');
       $stmt = $db->prepare("