Problem/Motivation
Fix introduced in #3535052: Deprecated function: ctype_digit()
Does not solve all the possible scenarios and the deprecation notice is still happening.
In our scenario, we have a view /foo/arg_0, where the empty arg lists all the possible items.
When accessing to /foo, we got the ctype_digit warning.
Values retrieved in line 101 are: Array
(
[0] => view_id
[1] => display_id
[2] => arg_0
)
But $lastSegment is NULL because $arg_0 route parameter is not set.
Then, we get the deprecation error.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork views_url_path_arguments-3540450
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
plopescComment #4
heddnCan we update the tests to cover this edge case?
Comment #6
jerech commentedI have added a kernel test to validate the fix applied in UrlPath.php, where the original condition was modified to avoid a deprecation warning when calling ctype_digit() with a NULL value. The new conditional first checks that $lastSegment is not empty before applying ctype_digit(), which resolves the reported issue when accessing a view such as /foo without the arg_0 parameter. To ensure that the plugin behaves correctly in all scenarios, I created the file tests/src/Kernel/NullUrlPathArgumentTest.php with two tests: testNullLastSegment, which simulates a path with arg_0 = NULL and confirms that the plugin returns an empty string without errors; and testNumericSegment, which verifies that a numeric argument such as ‘123’ is handled correctly and returned as is. Both tests pass successfully and confirm that the plugin now works safely and robustly. If further work is needed, I welcome comments and suggestions.
Comment #7
heddnThe test only changes didn't fail. So that means it isn't testing the issue or it would fail. NW
Comment #8
jerech commentedComment #9
heddn@plopesc can you verify the fixes offered now fix this problem?
Comment #10
plopesc@heddn The original patch provided has been in production for a while with no issues.
Tested the last version and it works for us.
Now that the MR includes tests, it should be even better!
Comment #12
heddn