Skip to content

[Filesystem] Path::getDirectory() doesn't retrieve the correct $dirSeparatorPosition with multibyte #47137

Closed
@Aangrod

Description

@Aangrod

Symfony version(s) affected

6.1, 6.2

Description

If a path has multibyte characters before the last directory separator, the returned path is cut at the wrong position.

How to reproduce

Run the following PHP codes :
Path::getDirectory("D:/Folder/Aééé/Subfolder");

It will return 'D:/Folder/Aééé/Su' instead of 'D:/Folder/Aééé'

Possible Solution

Replace strrpos with mb_strrpos at line 161 in Path.php :

if (false === ($dirSeparatorPosition = strrpos($path, '/'))) {
    return '';
}

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions