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

Bug: getSegments() returns an array with 2 empty strings when accessing / #2822

Closed
includebeer opened this issue Apr 12, 2020 · 1 comment
Closed
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@includebeer
Copy link

I have created a filter named 'Localize' in my CI4 app. In the before() function I call getSegments() on the request object. If I go to a URL containing some segments, like domain.com/fr or domain.com/fr/blog it work as expected. getTotalSegments will return 1 or 2, and getSegments will return an array with 'fr' or with 'fr and 'blog'.

The problem is when I go to the root of the website (domain.com), getTotalSegments will return 2 and getSegments will return an array containing 2 empty string:

DEBUG - 2020-04-12 16:27:23 --> ---- Filter Localize ----
DEBUG - 2020-04-12 16:27:23 --> getPath() = /
DEBUG - 2020-04-12 16:27:23 --> getTotalSegments() = 2
DEBUG - 2020-04-12 16:27:23 --> getSegments() = Array
(
    [0] => 
    [1] => 
)

DEBUG - 2020-04-12 16:27:25 --> ---- Filter Localize ----
DEBUG - 2020-04-12 16:27:25 --> getPath() = fr
DEBUG - 2020-04-12 16:27:25 --> getTotalSegments() = 1
DEBUG - 2020-04-12 16:27:25 --> getSegments() = Array
(
    [0] => fr
)

DEBUG - 2020-04-12 16:27:33 --> ---- Filter Localize ----
DEBUG - 2020-04-12 16:27:33 --> getPath() = fr/blog
DEBUG - 2020-04-12 16:27:33 --> getTotalSegments() = 2
DEBUG - 2020-04-12 16:27:33 --> getSegments() = Array
(
    [0] => fr
    [1] => blog
)

This is with CodeIgniter 4.0.2, PHP 7.4.2, Apache server (MAMP) on macOS.

Expected behavior would be 0 segments for URI /

DEBUG - 2020-04-12 16:27:23 --> ---- Filter Localize ----
DEBUG - 2020-04-12 16:27:23 --> getPath() = /
DEBUG - 2020-04-12 16:27:23 --> getTotalSegments() = 0
DEBUG - 2020-04-12 16:27:23 --> getSegments() = Array
(
)
@includebeer includebeer added the bug Verified issues on the current code behavior or pull requests that will fix them label Apr 12, 2020
@nyufeng nyufeng mentioned this issue Apr 15, 2020
5 tasks
@samsonasik
Copy link
Member

can be closed in favor of #2824

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

No branches or pull requests

3 participants