[wp-trac] [WordPress Trac] #41318: list_files() function bug

WordPress Trac noreply at wordpress.org
Fri Jul 14 01:41:07 UTC 2017


#41318: list_files() function bug
----------------------------+-----------------------------
 Reporter:  Tkama           |      Owner:
     Type:  enhancement     |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Filesystem API  |    Version:  4.8
 Severity:  normal          |   Keywords:
  Focuses:                  |
----------------------------+-----------------------------
 If we set first parameter of `list_files( $folder )` with trailing slash,
 we get incorrect paths in result. Example:

 {{{#!php
 <?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
 <?php
 function list_files( $folder = '', $levels = 100 ) {
     if ( empty($folder) )
         return false;

     $folder = untrailingslashit( $folder );

     ...
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41318>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list