Opened 7 years ago
Closed 7 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)
Change History (8)
#1
@
7 years ago
- Keywords needs-patch needs-unit-tests good-first-bug added
- Milestone changed from Awaiting Review to Future Release
#2
@
7 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
This ticket was mentioned in Slack in #core by desrosj. View the logs.
7 years ago
#4
@
7 years 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.
Created .diff