Skip to content

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

Merged
kenjis merged 3 commits into
codeigniter4:developfrom
kenjis:fix-url-to-empty-string
Oct 13, 2023
Merged

kenjis merged 3 commits into
codeigniter4:developfrom
kenjis:fix-url-to-empty-string

Conversation

@kenjis

@kenjis kenjis commented Oct 10, 2023

Copy link
Copy Markdown
Member

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

@MGatner MGatner left a comment

Copy link
Copy Markdown
Member

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.

Comment thread system/Router/RouteCollection.php
@kenjis

kenjis commented Oct 13, 2023

Copy link
Copy Markdown
Member Author

@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

MGatner commented Oct 13, 2023

Copy link
Copy Markdown
Member

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
@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