WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#41318 closed enhancement (fixed)

list_files() function bug

Reported by: Tkama Owned by:
Milestone: 4.9 Priority: normal
Severity: normal Version:
Component: Filesystem API Keywords:
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 3 years ago.
Created .diff
41318.1.patch (1.4 KB) - added by theorboman 3 years ago.
Patch with unit tests

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
3 years ago

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

@xkon
3 years ago

Created .diff

#2 @xkon
3 years 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 3 years ago by xkon (previous) (diff)

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


3 years ago

@theorboman
3 years ago

Patch with unit tests

#4 @theorboman
3 years ago

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

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

#5 @schlessera
3 years ago

  • Keywords close added; good-first-bug has-patch has-unit-tests removed

This bug was solved as part of #6531 and is not valid anymore for release 4.9.

#6 @dd32
3 years ago

  • Keywords close removed
  • Milestone changed from Future Release to 4.9
  • Resolution set to fixed
  • Status changed from new to closed
  • Version 4.8 deleted

This was effectively fixed through [41806]. I'm marking this as fixed in 4.9.

Note: See TracTickets for help on using tickets.