-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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: [Commands] routes
with {locale}
in route
#8152
fix: [Commands] routes
with {locale}
in route
#8152
Conversation
Okay, this is an improvement! Then, if |
There is a remark, such a check is only for the command. When used in other places (directly from classes), the filters will be Tests. I didn't understand what to check? An option without a locale and with it? Docs. My English is bad, we'll have to figure out what I'm going to write together🤔 |
At least, a test to check the changed output like |
Docs: you need to add changelog (Enhancement), and what the |
4f7d7d0
to
ebc2643
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. I did not take a good look at what was inside.
Changes to the behavior of the FilterFinder are not acceptable.
Please make the functionality happen without changing the FilterFinder.
@@ -50,6 +51,12 @@ public function find(string $uri): array | |||
{ | |||
$this->filters->reset(); | |||
|
|||
$isLocaleExist = strpos($uri, '{locale}') !== false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not acceptable.
Because the param $uri
is "URI path to find filters for".
{locale}/admin/settings
is not a URI path.
The URI path is like ja/admin/settings
or fr/admin/settings
.
This change will break the filter:check
command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See debug info.
// Routes.php
/**
* @var RouteCollection $routes
*/
$routes->useSupportedLocalesOnly(true);
$routes->get('/{locale}/home', 'Home::index');
// FilterFinder.php
public function find(string $uri): array
{
d($uri);
$this->filters->reset();
// Fix for the search filters command
$isSupportedLocaleOnly = false;
Set ja, fr crash my test.
1) CodeIgniter\Commands\Utilities\Routes\FilterFinderTest::testFindFiltersWithSupportedLocalesOnly
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
Array &0 (
'before' => Array &1 (
- 0 => '!csrf'
+ 0 => 'csrf'
)
'after' => Array &2 (
- 0 => '!toolbar'
+ 0 => 'toolbar'
)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And filter:checl normal output.
useSupportedLocalesOnly = true
$ ./spark filter:check get en/home
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 10:41:42 UTC+00:00
+--------+---------+----------------+---------------+
| Method | Route | Before Filters | After Filters |
+--------+---------+----------------+---------------+
| GET | en/home | | toolbar |
+--------+---------+----------------+---------------+
$ ./spark filter:check get ja/home
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 10:43:31 UTC+00:00
Can't find a route: "GET ja/home"
useSupportedLocalesOnly = false
$ ./spark filter:check get en/home
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 10:42:01 UTC+00:00
+--------+---------+----------------+---------------+
| Method | Route | Before Filters | After Filters |
+--------+---------+----------------+---------------+
| GET | en/home | | toolbar |
+--------+---------+----------------+---------------+
$ ./spark filter:check get ja/home
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 10:42:03 UTC+00:00
+--------+---------+----------------+---------------+
| Method | Route | Before Filters | After Filters |
+--------+---------+----------------+---------------+
| GET | ja/home | | toolbar |
+--------+---------+----------------+---------------+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. FilterFinder's responsibility is to find filters for a URI path.
If you pass {locale}/home
to it, it is a URI path of e.g., http://localhost/{locale}/home
.
It does not mean ja/home
or fr/home
.
Don't change the behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what the problem is... Is there a specific example with a behavior error?
Now everything is working correctly: with and without the useSupportedLocalesOnly
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We test route as useSupportedLocalesOnly = true/false
:
$ ./spark filter:check get {locale}/home
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 11:03:00 UTC+00:00
+--------+---------------+----------------+---------------+
| Method | Route | Before Filters | After Filters |
+--------+---------------+----------------+---------------+
| GET | {locale}/home | | !toolbar |
+--------+---------------+----------------+---------------+
$ ./spark filter:check get {locale}/home
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 11:03:22 UTC+00:00
+--------+---------------+----------------+---------------+
| Method | Route | Before Filters | After Filters |
+--------+---------------+----------------+---------------+
| GET | {locale}/home | | toolbar |
+--------+---------------+----------------+---------------+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter:check
should not output !
. It must always return actual filters to be applied.
$ php spark filter:check get {locale}/home
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 11:10:54 UTC+00:00
+--------+---------------+----------------+---------------+
| Method | Route | Before Filters | After Filters |
+--------+---------------+----------------+---------------+
| GET | {locale}/home | !invalidchars | !toolbar |
+--------+---------------+----------------+---------------+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not change the meaning of $uri
. It is the literal URI path, no meta characters or placeholders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is what we wanted, isn't it? Show POSSIBLE filters for a GROUP of languages. If you check the exact language everything will be fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is for routes
command. Not for filter:check
.
routes
will show inaccurate but useful filter info.
But filter:check
should always show accurate filter info.
Move to system/Commands/Utilities/Routes.php? |
Okay. I move code in
$ ./spark routes
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 12:10:00 UTC+00:00
+--------+---------------+------+------------------------------+----------------+---------------+
| Method | Route | Name | Handler | Before Filters | After Filters |
+--------+---------------+------+------------------------------+----------------+---------------+
| GET | / | » | \App\Controllers\Home::index | | toolbar |
| GET | {locale}/home | » | \App\Controllers\Home::index | | toolbar |
+--------+---------------+------+------------------------------+----------------+---------------+
$ ./spark routes
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 12:10:09 UTC+00:00
+--------+---------------+------+------------------------------+----------------+---------------+
| Method | Route | Name | Handler | Before Filters | After Filters |
+--------+---------------+------+------------------------------+----------------+---------------+
| GET | / | » | \App\Controllers\Home::index | | toolbar |
| GET | {locale}/home | » | \App\Controllers\Home::index | | !toolbar |
+--------+---------------+------+------------------------------+----------------+---------------+ And check routes allowed locale: $ ./spark filter:check get en/home
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 12:14:37 UTC+00:00
+--------+---------+----------------+---------------+
| Method | Route | Before Filters | After Filters |
+--------+---------+----------------+---------------+
| GET | en/home | | toolbar |
+--------+---------+----------------+---------------+
$ ./spark filter:check get en/home
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 12:14:45 UTC+00:00
+--------+---------+----------------+---------------+
| Method | Route | Before Filters | After Filters |
+--------+---------+----------------+---------------+
| GET | en/home | | toolbar |
+--------+---------+----------------+---------------+ Check routes unsupported locale: $ ./spark filter:check get ja/home
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 12:16:21 UTC+00:00
+--------+---------+----------------+---------------+
| Method | Route | Before Filters | After Filters |
+--------+---------+----------------+---------------+
| GET | ja/home | | toolbar |
+--------+---------+----------------+---------------+
$ ./spark filter:check get ja/home
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-06 12:16:28 UTC+00:00
Can't find a route: "GET ja/home" |
The following outputs are strange.
|
From the start, if the route key contains a regular expression, then the filters in spark routes are not 100% accurate. So, with the current spec, the output of spark routes, regardless of the value of If you want to be precise, you should change all filters for route keys containing regular expressions and |
Until now, I have not correctly identified the problem. Why don't we just change |
In message #8152 (comment)
In my opinion, it is normal that regular expressions have a I don't know what to do anymore. It seems that a small display causes such ambiguities. I think then let another person do it. |
I sent a PR #8167. Please try. |
544d392
to
4e872f7
Compare
You can close it. Functionality was not needed |
Closed by #8167 |
I sent PR #8178 to update the docs. |
Description
Fix #7997
Previously, the command output
<unknown>
for URLs with{locale}
instead of possible filters. Since there can be ~10 language options for one route. The commit adds !filtername to filters, which means probable application, but not guaranteed.Set
$routes->useSupportedLocalesOnly(true)
in app/Config/Routes.phpBefore:
After:
Checklist: