From b189147b9d1a113ca76320cacfdf182a1ff40b17 Mon Sep 17 00:00:00 2001
From: Justin Davis <jrcd83@gmail.com>
Date: Thu, 4 Nov 2010 10:35:19 -0700
Subject: [PATCH 1/3] Fix misleading bug report about UTF8 for an empty string.

Slight code reorganization as well.
---
 web/lib/aurjson.class.php |   35 +++++++++++++++++------------------
 1 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index 9ce51db..82db11b 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -146,26 +146,25 @@ class AurJSON {
 
         $result = db_query($base_query.$query_stub, $this->dbh);
 
-        if ( $result && (mysql_num_rows($result) > 0) ) {
-            $info_data = array();
-            while ($row = mysql_fetch_assoc($result)) {
-                foreach($row as $name => $value) {
-                    $converted = utf8_encode($value);
-                    if ($converted != "") {
-                        $row[$name] = $converted;
-                    }
-                    else {
-                        $row[$name] = "[PKGBUILD error: non-UTF8 character]";
-                    }
-                }
-                array_push($info_data, $row);
-            }
-            mysql_free_result($result);
-            return $this->json_results('info', $info_data);
-        }
-        else {
+        if ( !$result || mysql_num_rows($result) == 0 ) {
             return $this->json_error('No result found');
         }
+
+        $info_data = array();
+        while ( $row = mysql_fetch_assoc($result)) {
+            foreach ( $row as $name => $value ) {
+                /* Do not give misleading errors about empty strings */
+                if ( $value == "" ) continue;
+
+                $utf8_text = utf8_encode($value);
+                $row[$name] = ( $utf8_text == ""
+                                ? "[PKGBUILD error: non-UTF8 character]"
+                                : $utf8_text );
+            }
+            array_push($info_data, $row);
+        }
+        mysql_free_result($result);
+        return $this->json_results('info', $info_data);
     }
 
     /**
-- 
1.7.3

