diff --git a/core/event.php b/core/event.php index c9230d9a..65e5cdc0 100644 --- a/core/event.php +++ b/core/event.php @@ -91,9 +91,7 @@ class PageRequestEvent extends Event ); // break the path into parts - $args = explode('/', $path); - - $this->args = $args; + $this->args = explode('/', $path); } public function get_GET(string $key): ?string @@ -165,6 +163,11 @@ class PageRequestEvent extends Event return $value; } + public function page_starts_with(string $name): bool + { + return (count($this->args) >= 1) && ($this->args[0] == $name); + } + /** * Test if the requested path matches a given pattern. * diff --git a/ext/setup/main.php b/ext/setup/main.php index 78920c6e..04410707 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -324,7 +324,7 @@ class Setup extends Extension { global $config, $page, $user; - if ($event->page_matches("nicedebug")) { + if ($event->page_starts_with("nicedebug")) { $page->set_mode(PageMode::DATA); $page->set_data(json_encode_ex([ "args" => $event->args, diff --git a/ext/setup/test.php b/ext/setup/test.php index c1d9a057..de4f3668 100644 --- a/ext/setup/test.php +++ b/ext/setup/test.php @@ -16,6 +16,13 @@ class SetupTest extends ShimmiePHPUnitTestCase $this->assert_no_content("\n"); } + public function testNiceDebug(): void + { + // the automatic testing for shimmie2-examples depends on this + $page = $this->get_page('nicedebug/foo%2Fbar/1'); + $this->assertEquals('{"args":["nicedebug","foo%2Fbar","1"]}', $page->data); + } + public function testAuthAnon(): void { $this->assertException(PermissionDenied::class, function () {