[aur-dev] [PATCH 1/2] Simplify code to bound integer values
Suggested-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/html/pkgreq.php | 10 ++-------- web/lib/aur.inc.php | 13 +++++++++++++ web/lib/pkgfuncs.inc.php | 16 ++++------------ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/web/html/pkgreq.php b/web/html/pkgreq.php index 156645a..401b60c 100644 --- a/web/html/pkgreq.php +++ b/web/html/pkgreq.php @@ -21,19 +21,13 @@ if (!isset($base_id)) { /* Sanitize paging variables. */ if (isset($_GET['O'])) { - $_GET['O'] = intval($_GET['O']); - if ($_GET['O'] < 0) - $_GET['O'] = 0; + $_GET['O'] = max(intval($_GET['O']), 0); } else { $_GET['O'] = 0; } if (isset($_GET["PP"])) { - $_GET["PP"] = intval($_GET["PP"]); - if ($_GET["PP"] < 50) - $_GET["PP"] = 50; - else if ($_GET["PP"] > 250) - $_GET["PP"] = 250; + $_GET["PP"] = bound(intval($_GET["PP"]), 50, 250); } else { $_GET["PP"] = 50; } diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 3368696..7fa792b 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -584,3 +584,16 @@ function array_pkgbuild_merge($pkgbase_info, $section_info) { } return $pi; } + +/** + * Bound an integer value between two values + * + * @param int $n Integer value to bound + * @param int $min Lower bound + * @param int $max Upper bound + * + * @return int Bounded integer value + */ +function bound($n, $min, $max) { + return min(max($n, $min), $max); +} diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index f515864..7e65d09 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -519,22 +519,14 @@ function pkg_search_page($SID="") { /* Sanitize paging variables. */ if (isset($_GET['O'])) { - $_GET['O'] = intval($_GET['O']); - if ($_GET['O'] < 0) - $_GET['O'] = 0; - } - else { + $_GET['O'] = max(intval($_GET['O']), 0); + } else { $_GET['O'] = 0; } if (isset($_GET["PP"])) { - $_GET["PP"] = intval($_GET["PP"]); - if ($_GET["PP"] < 50) - $_GET["PP"] = 50; - else if ($_GET["PP"] > 250) - $_GET["PP"] = 250; - } - else { + $_GET["PP"] = bound(intval($_GET["PP"]), 50, 250); + } else { $_GET["PP"] = 50; } -- 2.0.1
Reported-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/pkgreqfuncs.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index 47758c3..69ba08d 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -35,7 +35,7 @@ function pkgreq_list() { * @param string $merge_into The target of a merge operation * @param string $comments The comments to be added to the request * - * @return void + * @return array Tuple of success/failure indicator and error message */ function pkgreq_file($ids, $type, $merge_into, $comments) { global $AUR_LOCATION; @@ -127,7 +127,7 @@ function pkgreq_file($ids, $type, $merge_into, $comments) { * @global string $AUR_REQUEST_ML The request notification mailing list * @param int $id The package request to close * - * @return void + * @return array Tuple of success/failure indicator and error message */ function pkgreq_close($id) { global $AUR_LOCATION; -- 2.0.1
participants (1)
-
Lukas Fleischer