summaryrefslogtreecommitdiffstats
path: root/web/lib
diff options
context:
space:
mode:
authorLukas Fleischer <archlinux@cryptocrack.de>2011-08-21 01:45:41 +0200
committerLukas Fleischer <archlinux@cryptocrack.de>2011-09-23 15:30:32 +0200
commit795971bc806776ad48de6f0135736cbaaefa5fcd (patch)
tree057c347f6cb1a24492dcf41e7d1940f19346db47 /web/lib
parent04a0fd47482f513c24645eb3f8b88b07303f9ec4 (diff)
downloadaur-795971bc806776ad48de6f0135736cbaaefa5fcd.tar.gz
aur-795971bc806776ad48de6f0135736cbaaefa5fcd.tar.xz
RPC: Coerce numeric values into integers
Coerce following fields into integers to ensure json_encode() serializes them as integers: * ID * CategoryID * NumVotes * OutOfDate * FirstSubmitted * LastModified This means that there will be a minor API break. There's no better way to do this properly, though. Fixes FS#25693. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/aurjson.class.php12
1 files changed, 12 insertions, 0 deletions
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index b4648c95..3a8e830f 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -22,6 +22,10 @@ class AurJSON {
'License', 'NumVotes', 'OutOfDateTS AS OutOfDate',
'SubmittedTS AS FirstSubmitted', 'ModifiedTS AS LastModified'
);
+ private static $numeric_fields = array(
+ 'ID', 'CategoryID', 'NumVotes', 'OutOfDate', 'FirstSubmitted',
+ 'LastModified'
+ );
/**
* Handles post data, and routes the request.
@@ -126,6 +130,14 @@ class AurJSON {
$name = $row['Name'];
$row['URLPath'] = URL_DIR . substr($name, 0, 2) . "/" . $name . "/" . $name . ".tar.gz";
+ /* Unfortunately, mysql_fetch_assoc() returns all fields as
+ * strings. We need to coerce numeric values into integers to
+ * provide proper data types in the JSON response.
+ */
+ foreach (self::$numeric_fields as $field) {
+ $row[$field] = intval($row[$field]);
+ }
+
if ($type == 'info') {
$search_data = $row;
break;