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

Command icon 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

plopesc created an issue. See original summary.

plopesc’s picture

Issue summary: View changes
Status: Active » Needs review
heddn’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Can we update the tests to cover this edge case?

jeremy1606 made their first commit to this issue’s fork.

jerech’s picture

Status: Needs work » Needs review

I 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.

heddn’s picture

Status: Needs review » Needs work

The test only changes didn't fail. So that means it isn't testing the issue or it would fail. NW

jerech’s picture

Status: Needs work » Needs review
heddn’s picture

@plopesc can you verify the fixes offered now fix this problem?

plopesc’s picture

Status: Needs review » Reviewed & tested by the community

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

  • heddn committed 238494c1 on 8.x-1.x authored by plopesc
    feat: #3540450 3535052 Deprecated function: ctype_digit()
    
    By: plopesc...
heddn’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.