Merge pull request #21570 from woocommerce/fix/21542

Fix: Posted variation attribute values not recognized if "+" present
This commit is contained in:
Claudiu Lodromanean 2018-10-15 10:02:46 -07:00 committed by GitHub
commit 76ae5382a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -2776,7 +2776,7 @@ if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) {
// Get selected value.
if ( false === $args['selected'] && $args['attribute'] && $args['product'] instanceof WC_Product ) {
$selected_key = 'attribute_' . sanitize_title( $args['attribute'] );
$args['selected'] = isset( $_REQUEST[ $selected_key ] ) ? wc_clean( urldecode( wp_unslash( $_REQUEST[ $selected_key ] ) ) ) : $args['product']->get_variation_default_attribute( $args['attribute'] ); // WPCS: input var ok, CSRF ok, sanitization ok.
$args['selected'] = isset( $_REQUEST[ $selected_key ] ) ? wc_clean( wp_unslash( $_REQUEST[ $selected_key ] ) ) : $args['product']->get_variation_default_attribute( $args['attribute'] ); // WPCS: input var ok, CSRF ok, sanitization ok.
}
$options = $args['options'];

View File

@ -65,4 +65,39 @@ class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
$product->delete( true );
wp_delete_term( $category['term_id'], 'product_cat' );
}
public function test_wc_dropdown_variation_attribute_options_no_attributes() {
$this->expectOutputString( '<select id="" class="" name="attribute_" data-attribute_name="attribute_" data-show_option_none="yes"><option value="">Choose an option</option></select>' );
wc_dropdown_variation_attribute_options();
}
public function test_wc_dropdown_variation_attribute_options_should_return_attributes_list() {
$product = WC_Helper_Product::create_variation_product();
$this->expectOutputString( '<select id="pa_size" class="" name="attribute_pa_size" data-attribute_name="attribute_pa_size" data-show_option_none="yes"><option value="">Choose an option</option><option value="large" >large</option><option value="small" >small</option></select>' );
wc_dropdown_variation_attribute_options(
array(
'product' => $product,
'attribute' => 'pa_size',
)
);
}
public function test_wc_dropdown_variation_attribute_options_should_return_attributes_list_and_selected_element() {
$product = WC_Helper_Product::create_variation_product();
$_REQUEST['attribute_pa_size'] = 'large';
$this->expectOutputString( '<select id="pa_size" class="" name="attribute_pa_size" data-attribute_name="attribute_pa_size" data-show_option_none="yes"><option value="">Choose an option</option><option value="large" selected=\'selected\'>large</option><option value="small" >small</option></select>' );
wc_dropdown_variation_attribute_options(
array(
'product' => $product,
'attribute' => 'pa_size',
)
);
unset( $_REQUEST['attribute_pa_size'] );
}
}