Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: route with "/" respond in any method [GET, POST, PUT, etc] #9217

Open
nicojmb opened this issue Oct 7, 2024 · 2 comments
Open

Bug: route with "/" respond in any method [GET, POST, PUT, etc] #9217

nicojmb opened this issue Oct 7, 2024 · 2 comments
Labels
waiting for info Issues or pull requests that need further clarification from the author

Comments

@nicojmb
Copy link

nicojmb commented Oct 7, 2024

PHP Version

8.3

CodeIgniter4 Version

4.5.5

CodeIgniter4 Installation Method

Manual (zip or tar.gz)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

fpm-fcgi

Database

MariaDB

What happened?

Hi,
I've these routes:
image

In postman if i execute:

GET --> /api/devices --> Respond OK
POST --> /api/devices --> Respond OK
DELETE --> /api/devices --> Respond ERROR (it's normal not exists route)

image

but if i execute with and slash "/" at the end, all routes respond as if they were GET.

GET --> /api/devices/ --> Respond OK
POST --> /api/devices/ --> Respond OK
DELETE --> /api/devices/ --> Respond OK

image

and I can't find where the problem is

Steps to Reproduce

Make a postman call with adding a slash to the end

Expected Output

Same answer whether it has a slash or not

Anything else?

No response

@nicojmb nicojmb added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 7, 2024
@ddevsr
Copy link
Collaborator

ddevsr commented Oct 22, 2024

I cannot reproduce bug

$ git diff tests/system/Router/RouterTest.php
diff --git a/tests/system/Router/RouterTest.php b/tests/system/Router/RouterTest.php
index bb5302e721..212294c3d2 100644
--- a/tests/system/Router/RouterTest.php
+++ b/tests/system/Router/RouterTest.php
@@ -716,6 +716,34 @@ final class RouterTest extends CIUnitTestCase
         $this->assertSame('auth_post', $router->methodName());
     }
 
+    public function testRouteEndSlash(): void
+    {
+        $this->collection->post('api/devices', 'Main::auth_post');
+        $this->collection->get('api/devices', 'Main::index');
+        $router = new Router($this->collection, $this->request);
+
+        $this->collection->setHTTPVerb(Method::POST);
+
+        $router->handle('api/devices');
+        $this->assertSame('\Main', $router->controllerName());
+        $this->assertSame('auth_post', $router->methodName());
+
+        $this->collection->setHTTPVerb(Method::GET);
+
+        $router->handle('api/devices');
+        $this->assertSame('\Main', $router->controllerName());
+        $this->assertSame('index', $router->methodName());
+
+        $this->collection->setHTTPVerb(Method::DELETE);
+
+        $router->handle('api/devices/');
+        $this->assertSame('\Main', $router->controllerName());
+        $this->assertSame('index', $router->methodName());
+    }
+
$ vendor/bin/phpunit tests/system/Router/RouterTest.php
PHPUnit 11.4.2 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.12 with Xdebug 3.3.2
Configuration: D:\Project\laragon\www\ci4\phpunit.xml.dist

........................................E...................                                                                                  60 / 60 (100%)

Time: 00:01.434, Memory: 20.00 MB

There was 1 error:

1) CodeIgniter\Router\RouterTest::testMultipleThree
CodeIgniter\Exceptions\PageNotFoundException: Can't find a route for 'DELETE: api/devices/'.

D:\Project\laragon\www\ci4\system\Router\Router.php:222
D:\Project\laragon\www\ci4\tests\system\Router\RouterTest.php:742

ERRORS!
Tests: 60, Assertions: 161, Errors: 1, PHPUnit Deprecations: 1.

Generating code coverage report in Clover XML format ... done [00:00.923]

Generating code coverage report in HTML format ... done [00:07.057]

@ddevsr ddevsr added waiting for info Issues or pull requests that need further clarification from the author and removed bug Verified issues on the current code behavior or pull requests that will fix them labels Oct 22, 2024
@ddevsr
Copy link
Collaborator

ddevsr commented Oct 22, 2024

@nicojmb can you share configuration in app/Config/Routes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for info Issues or pull requests that need further clarification from the author
Projects
None yet
Development

No branches or pull requests

2 participants