8000 [Filesystem] Path::getDirectory() doesn't retrieve the correct $dirSeparatorPosition with multibyte · Issue #47137 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

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

Closed
Aangrod opened this issue Aug 1, 2022 · 1 comment

Comments

@Aangrod
Copy link
Aangrod commented Aug 1, 2022

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

@xabbuh
Copy link
Member
xabbuh commented Aug 2, 2022

Status: Reviewed

nicolas-grekas added a commit that referenced this issue Aug 2, 2022
This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[Filesystem] Remove needless `mb_*` calls

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #47137
| License       | MIT
| Doc PR        | None

Issue fixed by adjusting to mb_strrpos to return expected index.

Commits
-------

07242cc [Filesystem] Remove needless `mb_*` calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0