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

feat: throws exception when controller name in routes contains / #5885

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Apr 9, 2022

Description

  • Throws Exception when a routes has invalid controller name like 'Admin/AdminGlavni::cam_edit_show/$1'

It is better users know it should be \ than replacing / with \ without notice.
Because Admin/AdminGlavni is a wrong classname.

See https://forum.codeigniter.com/showthread.php?tid=81681&pid=395315#pid395315

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 enhancement PRs that improve existing functionalities label Apr 9, 2022
@@ -426,6 +426,11 @@ protected function checkRoutes(string $uri): bool
throw RouterException::forDynamicController($handler);
}

// Checks `/` in controller name
if (strpos($controller, '/') !== false) {
Copy link
Member

Choose a reason for hiding this comment

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

I wasn't able to find parameters for "valid PHP class names", but would it make sense to expand this out to a regex and fail anything that didn't fit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Admin/AdminGlavni is not a valid PHP class name.
Because / is wrong.

Many users write like 'Admin/AdminGlavni::cam_edit_show/$1' and CI4 causes errors.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I get that. My question was: is there any reason why not to make this check for all class names? Admin\Admin-Glavni is also not valid. This could be implemented as a filter and the error as "Your controller contains the following invalid characters: -"

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it is a breaking change.
Admin/AdminGlavni is not valid, but works now.

@kenjis kenjis merged commit 86ab911 into codeigniter4:develop Apr 12, 2022
@kenjis kenjis deleted the feat-exception-router-invalid-controller-name branch April 12, 2022 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement PRs that improve existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants