From f7bba5cbcdd152c13e28f8ddd1ac122cfd04f4f6 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 16 Sep 2026 14:18:09 +0000 Subject: [PATCH] fix(admin): saving an edit from the new UI answered an empty page post.php hands its optional `referer` parameter to AdminHelpers::getPageFromURL() on every edit (streams, movies, created channels, episodes, lines, MAG, Enigma2, radios, series, resellers). The new-UI forms post without one, and the `string` type the cs-fix pass (758a9cab) put on the parameter turned that null into a TypeError: the save answered an empty 200 and the form showed its error toast. Found by the new E2E line-edit test. The function already treated an empty URL as "no page"; it now takes null the same way, and a URL without a path no longer reads an undefined `path` key. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_016WDhDajBPziJwjWZcXnh6R --- src/Core/Util/AdminHelpers.php | 12 +++++++----- tests/Unit/AdminHelpersTest.php | 10 ++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Core/Util/AdminHelpers.php b/src/Core/Util/AdminHelpers.php index 85cb27c7..fcd16950 100644 --- a/src/Core/Util/AdminHelpers.php +++ b/src/Core/Util/AdminHelpers.php @@ -359,12 +359,14 @@ class AdminHelpers { /** * Extract the page name (script basename) from a URL. * - * @param string $rURL URL to parse. - * @return string|null Lowercased page name, or null if $rURL is empty. + * @param string|null $rURL URL to parse. post.php passes its optional + * `referer` parameter, which the new-UI forms omit. + * @return string|null Lowercased page name, or null if $rURL is empty or has no path. */ - public static function getPageFromURL(string $rURL) { - if ($rURL) { - return strtolower(basename(ltrim(parse_url($rURL)['path'], '/'), '.php')); + public static function getPageFromURL(?string $rURL) { + $rPath = $rURL ? parse_url($rURL, PHP_URL_PATH) : null; + if (is_string($rPath) && trim($rPath, '/') !== '') { + return strtolower(basename(ltrim($rPath, '/'), '.php')); } return null; diff --git a/tests/Unit/AdminHelpersTest.php b/tests/Unit/AdminHelpersTest.php index fcefd5d5..b0f86f0a 100644 --- a/tests/Unit/AdminHelpersTest.php +++ b/tests/Unit/AdminHelpersTest.php @@ -64,6 +64,16 @@ final class AdminHelpersTest extends TestCase { $this->assertNull(AdminHelpers::getPageFromURL('')); } + /** + * post.php hands over its `referer` parameter, which the new-UI forms do not + * send: a null there must read as "no page", not end the request. + */ + public function testGetPageFromUrlWithoutAReferer() { + $this->assertNull(AdminHelpers::getPageFromURL(null)); + $this->assertSame('lines', AdminHelpers::getPageFromURL('lines?status=1')); + $this->assertNull(AdminHelpers::getPageFromURL('http://host')); + } + public function testProtocolDetectionFromServerVars() { $saved = $_SERVER;