Merge pull request #13764 from woocommerce/fix-13750

Support (not really) relative paths
This commit is contained in:
Claudio Sanches 2017-03-24 11:16:48 -03:00 committed by GitHub
commit 1147c4f5b3
2 changed files with 6 additions and 0 deletions

View File

@ -205,6 +205,10 @@ class WC_Download_Handler {
$remote_file = false; $remote_file = false;
$file_path = ABSPATH . $file_path; $file_path = ABSPATH . $file_path;
} elseif ( '/wp-content' === substr( $file_path, 0, 11 ) ) {
$remote_file = false;
$file_path = realpath( WP_CONTENT_DIR . substr( $file_path, 11 ) );
// Check if we have an absolute path // Check if we have an absolute path
} elseif ( ( ! isset( $parsed_file_path['scheme'] ) || ! in_array( $parsed_file_path['scheme'], array( 'http', 'https', 'ftp' ) ) ) && isset( $parsed_file_path['path'] ) && file_exists( $parsed_file_path['path'] ) ) { } elseif ( ( ! isset( $parsed_file_path['scheme'] ) || ! in_array( $parsed_file_path['scheme'], array( 'http', 'https', 'ftp' ) ) ) && isset( $parsed_file_path['path'] ) && file_exists( $parsed_file_path['path'] ) ) {
$remote_file = false; $remote_file = false;

View File

@ -97,6 +97,8 @@ class WC_Product_Download implements ArrayAccess {
$file_url = $this->get_file(); $file_url = $this->get_file();
if ( '..' === substr( $file_url, 0, 2 ) || '/' !== substr( $file_url, 0, 1 ) ) { if ( '..' === substr( $file_url, 0, 2 ) || '/' !== substr( $file_url, 0, 1 ) ) {
$file_url = realpath( ABSPATH . $file_url ); $file_url = realpath( ABSPATH . $file_url );
} elseif ( '/wp-content' === substr( $file_url, 0, 11 ) ) {
$file_url = realpath( WP_CONTENT_DIR . substr( $file_url, 11 ) );
} }
return apply_filters( 'woocommerce_downloadable_file_exists', file_exists( $file_url ), $this->get_file() ); return apply_filters( 'woocommerce_downloadable_file_exists', file_exists( $file_url ), $this->get_file() );
} }