mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 09:43:03 +00:00
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>
This commit is contained in:
parent
04a0fd4748
commit
795971bc80
1 changed files with 12 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue