mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-03 20:02:29 +02:00
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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WDhDajBPziJwjWZcXnh6R
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user