From e750448f5b32982170f81ca045f9f7e8dc8eed6f Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 22 Mar 2023 09:57:31 +0100 Subject: Consistent entry ID type (32-bit compatibility) (#5213) * Remove FreshRSS_Searchable for better types The interface was not used, and it was preventing more precise types for the different `searchById()` methods, as they each have different input and output types. * Consistent entry ID Entry IDs (which are 64-bit integers) must be processed as string to be compatible with 32-bit platforms * Fix type * A few more related types * PHPStan level 6 * Some more casts needed * String cast for htmlspecialchars --- p/api/greader.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 069f37b65..a4b542c23 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -385,10 +385,6 @@ final class GReaderAPI { self::badRequest(); } $addCatId = 0; - $categoryDAO = null; - if ($add != '' || $remove != '') { - $categoryDAO = FreshRSS_Factory::createCategoryDao(); - } $c_name = ''; if ($add != '' && strpos($add, 'user/') === 0) { //user/-/label/Example ; user/username/label/Example if (strpos($add, 'user/-/label/') === 0) { @@ -403,6 +399,7 @@ final class GReaderAPI { } } $c_name = htmlspecialchars($c_name, ENT_COMPAT, 'UTF-8'); + $categoryDAO = FreshRSS_Factory::createCategoryDao(); $cat = $categoryDAO->searchByName($c_name); $addCatId = $cat == null ? 0 : $cat->id(); } elseif ($remove != '' && strpos($remove, 'user/-/label/') === 0) { @@ -586,13 +583,14 @@ final class GReaderAPI { } /** - * @return array + * @param string|int $streamId + * @return array{string,int,int,FreshRSS_BooleanSearch} */ - private static function streamContentsFilters(string $type, string $streamId, + private static function streamContentsFilters(string $type, $streamId, string $filter_target, string $exclude_target, int $start_time, int $stop_time): array { switch ($type) { case 'f': //feed - if ($streamId != '' && !ctype_digit($streamId)) { + if ($streamId != '' && is_string($streamId) && !ctype_digit($streamId)) { $feedDAO = FreshRSS_Factory::createFeedDao(); $streamId = htmlspecialchars($streamId, ENT_COMPAT, 'UTF-8'); $feed = $feedDAO->searchByUrl($streamId); @@ -601,7 +599,7 @@ final class GReaderAPI { break; case 'c': //category or label $categoryDAO = FreshRSS_Factory::createCategoryDao(); - $streamId = htmlspecialchars($streamId, ENT_COMPAT, 'UTF-8'); + $streamId = htmlspecialchars((string)$streamId, ENT_COMPAT, 'UTF-8'); $cat = $categoryDAO->searchByName($streamId); if ($cat != null) { $type = 'c'; @@ -619,6 +617,7 @@ final class GReaderAPI { } break; } + $streamId = (int)$streamId; switch ($filter_target) { case 'user/-/state/com.google/read': -- cgit v1.2.3