From ccdf6d02530f5f18b968542d21de36d8a2a2b899 Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Mon, 15 Oct 2018 13:50:34 -0700 Subject: [PATCH] Simplified path check for CSV importer to cause less issues --- ...ass-wc-product-csv-importer-controller.php | 2 +- tests/unit-tests/importer/product.php | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index affa25fcaa0..30535224c7b 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -91,7 +91,7 @@ class WC_Product_CSV_Importer_Controller { * @return bool */ public static function is_file_valid_csv( $file, $check_path = true ) { - if ( $check_path && apply_filters( 'woocommerce_product_csv_importer_check_import_file_path', true ) && 0 !== stripos( $file, ABSPATH ) ) { + if ( $check_path && apply_filters( 'woocommerce_product_csv_importer_check_import_file_path', true ) && false !== stripos( $file, '://' ) ) { return false; } diff --git a/tests/unit-tests/importer/product.php b/tests/unit-tests/importer/product.php index f039988646a..fef5b832533 100644 --- a/tests/unit-tests/importer/product.php +++ b/tests/unit-tests/importer/product.php @@ -27,16 +27,6 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case { $bootstrap = WC_Unit_Tests_Bootstrap::instance(); require_once $bootstrap->plugin_dir . '/includes/import/class-wc-product-csv-importer.php'; require_once $bootstrap->plugin_dir . '/includes/admin/importers/class-wc-product-csv-importer-controller.php'; - - add_filter( 'woocommerce_product_csv_importer_check_import_file_path', '__return_false' ); - } - - /** - * Remove filters. - */ - public function tearDown() { - parent::tearDown(); - remove_filter( 'woocommerce_product_csv_importer_check_import_file_path', '__return_false' ); } /** @@ -624,4 +614,14 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case { return $mocked_response; } + + /** + * Test WC_Product_CSV_Importer_Controller::is_file_valid_csv. + */ + public function test_is_file_valid_csv() { + $this->assertTrue( WC_Product_CSV_Importer_Controller::is_file_valid_csv( 'C:/wamp64/www/test.local/wp-content/uploads/2018/10/products_all_gg-1.csv' ) ); + $this->assertTrue( WC_Product_CSV_Importer_Controller::is_file_valid_csv( '/srv/www/woodev/wp-content/uploads/2018/10/1098488_single.csv' ) ); + $this->assertFalse( WC_Product_CSV_Importer_Controller::is_file_valid_csv( '/srv/www/woodev/wp-content/uploads/2018/10/img.jpg' ) ); + $this->assertFalse( WC_Product_CSV_Importer_Controller::is_file_valid_csv( 'file:///srv/www/woodev/wp-content/uploads/2018/10/1098488_single.csv' ) ); + } }