Slim: Routing bug?

Here I have setup my routes.php

$app->get('/[{name}]', 'App\Actions\HomeAction:index')->setName('home-page');

and here my index method in action class

public function index($req, $res, $args)
{
    if (isset($args['name'])) {
        return $this->view->render('hello', [
            'name' => $args['name'],
            'desc' => 'Welcome to world',
        ]);
    }
    return $this->view->render('home');
}

and sure it works as expected

Request URI Response
example.com[/] render home template
example.com/foobar render hallo template, with $args['name'] = 'foobar'
example.com/foo/bar return not found

but I don’t expect it could work like this.

Request URI Response
example.com// render home template
example.com//foo render home template
example.com//foo/bar render hallo template, with $args['name'] = 'bar'
example.com//foo/bar/bas return not found
example.com///foo render home template
example.com///foo/bar render home template
example.com///foo/bar/bas render home template

Is it a bug?

EDIT: I’m using local ubuntu server with nginx

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

haha…

This function is intended specifically for the purpose of parsing URLs and not URIs.

That documentation snippet explains where we got the idea to use parse_url()!

However, the documentation for parse_url says:

Note: This function doesn’t work with relative URLs.

I’m pretty sure that using parse_url is wrong in this case and this line should be:

$requestUri = $env->get('REQUEST_URI');

Thoughts @codeguy, @silentworks?