WordPress.org

Make WordPress Core

Opened 8 weeks ago

Last modified 4 weeks ago

#41318 new enhancement

list_files() function bug

Reported by: Tkama Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.8
Component: Filesystem API Keywords: good-first-bug has-patch has-unit-tests
Focuses: Cc:

Description

If we set first parameter of list_files( $folder ) with trailing slash, we get incorrect paths in result. Example:

<?php
$files = list_files( ABSPATH );

print_r( $files );

/*
Array
(
    [0] => /home/t/tkamab32/wp-kama.ru/public_html//xmlrpc.php
    [1] => /home/t/tkamab32/wp-kama.ru/public_html//wp-mail.php
    [2] => /home/t/tkamab32/wp-kama.ru/public_html//wp-includes/ms-settings.php
    ...
*/

We see double slash // in path...

Maybe better to filter incoming $folder parametr with untrailingslashit():

<?php
function list_files( $folder = '', $levels = 100 ) {
    if ( empty($folder) )
        return false;

    $folder = untrailingslashit( $folder );

    ...

Attachments (2)

41318.diff (446 bytes) - added by xkon 8 weeks ago.
Created .diff
41318.1.patch (1.4 KB) - added by theorboman 4 weeks ago.
Patch with unit tests

Download all attachments as: .zip

Change History (6)

#1 @SergeyBiryukov
8 weeks ago

  • Keywords needs-patch needs-unit-tests good-first-bug added
  • Milestone changed from Awaiting Review to Future Release

@xkon
8 weeks ago

Created .diff

#2 @xkon
8 weeks ago

  • Keywords has-patch added; needs-patch removed

Created a diff as the original author proposed for easier access & testing.

I also run some tests with various folder configurations without seeing any problems. So probably it's good to go as well.

Best regards,
Konstantinos

Last edited 8 weeks ago by xkon (previous) (diff)

This ticket was mentioned in Slack in #core by desrosj. View the logs.


6 weeks ago

@theorboman
4 weeks ago

Patch with unit tests

#4 @theorboman
4 weeks ago

  • Keywords has-unit-tests added; needs-unit-tests removed

I've added another patch with some pretty simple unit tests for this.

Note: See TracTickets for help on using tickets.