From e5cc7a5ab1229ff341a64f02d883b6ee5159b1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 20 Jun 2022 08:25:17 +0200 Subject: [PATCH] Fixes: - Strings::isHex() should not be misused for checking on NULL --- mod/photos.php | 6 +++--- tests/src/Util/StringsTest.php | 10 +++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 0e2299770a..977cebf20d 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -187,7 +187,7 @@ function photos_post(App $a) } if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'album') { - if (!Strings::isHex(DI::args()->getArgv()[3])) { + if (!Strings::isHex(DI::args()->getArgv()[3] ?? '')) { DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album'); } $album = hex2bin(DI::args()->getArgv()[3]); @@ -892,7 +892,7 @@ function photos_content(App $a) return; } - $selname = Strings::isHex($datum) ? hex2bin($datum) : ''; + $selname = (!is_null($datum) && Strings::isHex($datum)) ? hex2bin($datum) : ''; $albumselect = ''; @@ -954,7 +954,7 @@ function photos_content(App $a) // Display a single photo album if ($datatype === 'album') { // if $datum is not a valid hex, redirect to the default page - if (!Strings::isHex($datum)) { + if (is_null($datum) || !Strings::isHex($datum)) { DI::baseUrl()->redirect('photos/' . $user['nickname']. '/album'); } $album = hex2bin($datum); diff --git a/tests/src/Util/StringsTest.php b/tests/src/Util/StringsTest.php index 6f0fc32fe3..67a8aa259c 100644 --- a/tests/src/Util/StringsTest.php +++ b/tests/src/Util/StringsTest.php @@ -113,22 +113,18 @@ class StringsTest extends TestCase 'input' => '', 'valid' => false, ], - 'nullHex' => [ - 'input' => null, - 'valid' => false, - ], ]; } /** * Tests if the string is a valid hexadecimal value * - * @param string|null $input - * @param bool $valid + * @param string $input + * @param bool $valid * * @dataProvider dataIsHex */ - public function testIsHex(string $input = null, bool $valid = false) + public function testIsHex(string $input = '', bool $valid = false) { self::assertEquals($valid, Strings::isHex($input)); }