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

Properly escape path separator in tar.php file list regex #1562

Merged
merged 1 commit into from
Apr 28, 2024

Conversation

sevmonster
Copy link

@sevmonster sevmonster commented Apr 26, 2024

In tar.php, the regex delimiter / is not properly escaped when building the $files regex list. This results in the incorrect regex /^(snappymail/)/u on my system. I don't know why seemingly no one else has run into this as I have been unable to find any GH issues related to it. For reference I am running Alpine Linux which uses the Busybox userland and musl libc.

This PR replaces the array_map callable with an anonymous function that adds the delimiter argument to preg_quote. The bad regex above is correctly translated into /^(snappymail\/)/u after applying the patch.

@the-djmaze
Copy link
Owner

https://www.php.net/preg_quote

The special regular expression characters are: . \ + * ? [ ^ ] $ ( ) { } = ! < > | : - #
Note that / is not a special regular expression character.

So this will also work:

$files = '#^(' . \implode('|', \array_map('preg_quote', \is_array($files) ? $files : [$files])) . ')#u';

@the-djmaze the-djmaze merged commit 0c081cf into the-djmaze:master Apr 28, 2024
the-djmaze pushed a commit that referenced this pull request Apr 28, 2024
@the-djmaze the-djmaze added the bug Something isn't working label Apr 28, 2024
@sevmonster sevmonster deleted the patch-1 branch April 29, 2024 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants