[aur-dev] [PATCH 3/3] JSON-RPC: convert null and "" in info queries.

Christopher Brannon chris at the-brannons.com
Fri Nov 5 18:28:30 CET 2010


When processing a query of type=info, the code in aurjson.class.php
was not gracefully coping with attributes which have a value of null
or the empty string.
For example, if the URL field of an object was "",
the JSON-encoded result would contain:
{"URLPath":"[PKGBUILD error: non-UTF8 character]"}
This patch insures that NULL and "" are handled properly.
---
 web/lib/aurjson.class.php |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index c5bb728..193122d 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -154,12 +154,14 @@ class AurJSON {
             $row = mysql_fetch_assoc($result);
             mysql_free_result($result);
             foreach($row as $name => $value) {
-                $converted = utf8_encode($value);
-                if ($converted != "") {
-                    $row[$name] = $converted;
-                }
-                else {
-                    $row[$name] = "[PKGBUILD error: non-UTF8 character]";
+                if (($value != NULL) && ($value != "")) {
+                    $converted = utf8_encode($value);
+                    if ($converted != "") {
+                        $row[$name] = $converted;
+                    }
+                    else {
+                        $row[$name] = "[PKGBUILD error: non-UTF8 character]";
+                    }
                 }
             }
             return $this->json_results('info', $row);
-- 
1.7.3.2



More information about the aur-dev mailing list