Skip to content

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

Description

@includebeer

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
(
)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions