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

fix: reverse route for '' is not false #8024

Merged
merged 3 commits into from
Oct 13, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Oct 10, 2023

Description

By default, the following code returns http://localhost:8080/index.php/ (the first route).

<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index(): string
    {
        dd(url_to(''));
    }
}

There is a test case for an empty string:

public function testUrlToThrowsOnEmptyOrMissingRoute(string $route): void

But it passes because no route is registered at the test execution.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 10, 2023
@kenjis kenjis changed the title fix: reverse route for '' is invalid fix: reverse route for '' is not false Oct 10, 2023
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide more justification why '' would not logically be the route to "default URL"? I assume '/' already is. There is some precedent in RFCs to treat these as identical.

system/Router/RouteCollection.php Show resolved Hide resolved
@kenjis
Copy link
Member Author

kenjis commented Oct 13, 2023

@MGatner This is about Reverse Routing, not URI path.
So the parameter is a Controller::method or route name.

The '' is invalid as Controller::method or route name.

@MGatner
Copy link
Member

MGatner commented Oct 13, 2023

Ohhh sorry, didn't read closely enough! Yes clearly a bug, thanks for clarifying.

@kenjis kenjis merged commit 50bd285 into codeigniter4:develop Oct 13, 2023
60 checks passed
@kenjis kenjis deleted the fix-url-to-empty-string branch October 13, 2023 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants