Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security fix: Backport security fixes from WC 3.5.7 #229

Merged
merged 4 commits into from
Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions assets/js/admin/meta-boxes-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ jQuery( function ( $ ) {
input_name = $state.attr( 'name' ),
input_id = $state.attr( 'id' ),
value = $this.data( 'woocommerce.stickState-' + country ) ? $this.data( 'woocommerce.stickState-' + country ) : $state.val(),
placeholder = $state.attr( 'placeholder' );
placeholder = $state.attr( 'placeholder' ),
$newstate;

if ( stickValue ){
$this.data( 'woocommerce.stickState-' + country, value );
Expand All @@ -53,22 +54,37 @@ jQuery( function ( $ ) {
$parent.show().find( '.select2-container' ).remove();

if ( ! $.isEmptyObject( wc_meta_boxes_order.states[ country ] ) ) {
var $states_select = $( '<select name="' + input_name + '" id="' + input_id + '" class="js_field-state select short" placeholder="' + placeholder + '"></select>' ),
state = wc_meta_boxes_order.states[ country ];

$states_select.append( $( '<option value="">' + woocommerce_admin_meta_boxes_order.i18n_select_state_text + '</option>' ) );

$.each( state, function( index ) {
$states_select.append( $( '<option value="' + index + '">' + state[ index ] + '</option>' ) );
} );
var state = wc_meta_boxes_order.states[ country ],
$defaultOption = $( '<option value=""></option>' )
.text( woocommerce_admin_meta_boxes_order.i18n_select_state_text );

$newstate = $( '<select></select>' )
.prop( 'id', input_id )
.prop( 'name', input_name )
.prop( 'placeholder', placeholder )
.addClass( 'js_field-state select short' )
.append( $defaultOption );

$.each( state, function( index ) {
var $option = $( '<option></option>' )
.prop( 'value', index )
.text( state[ index ] );
$newstate.append( $option );
} );

$states_select.val( value );
$newstate.val( value );

$state.replaceWith( $states_select );
$state.replaceWith( $newstate );

$states_select.show().selectWoo().hide().change();
$newstate.show().selectWoo().hide().change();
} else {
$state.replaceWith( '<input type="text" class="js_field-state" name="' + input_name + '" id="' + input_id + '" value="' + value + '" placeholder="' + placeholder + '" />' );
$newstate = $( '<input type="text" />' )
.prop( 'id', input_id )
.prop( 'name', input_name )
.prop( 'placeholder', placeholder )
.addClass( 'js_field-state' )
.val( value );
$state.replaceWith( $newstate );
}

// This event has a typo - deprecated in 2.5.0
Expand Down Expand Up @@ -641,7 +657,7 @@ jQuery( function ( $ ) {
items: $( 'table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]' ).serialize(),
security: woocommerce_admin_meta_boxes.calc_totals_nonce
} );

$( document.body ).trigger( 'order-totals-recalculate-before', data );

$.ajax({
Expand Down Expand Up @@ -750,7 +766,7 @@ jQuery( function ( $ ) {
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
if ( true === response.success ) {
// Redirect to same page for show the refunded status
window.location.href = window.location.href;
window.location.reload();
} else {
window.alert( response.data.error );
wc_meta_boxes_order_items.reload_items();
Expand Down
55 changes: 33 additions & 22 deletions assets/js/frontend/country-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,47 +93,58 @@ jQuery( function( $ ) {
input_name = $statebox.attr( 'name' ),
input_id = $statebox.attr( 'id' ),
value = $statebox.val(),
placeholder = $statebox.attr( 'placeholder' ) || $statebox.attr( 'data-placeholder' ) || '';

placeholder = $statebox.attr( 'placeholder' ) || $statebox.attr( 'data-placeholder' ) || '',
$newstate;
if ( states[ country ] ) {
if ( $.isEmptyObject( states[ country ] ) ) {

$statebox.closest( 'p.form-row' ).hide().find( '.select2-container' ).remove();
$statebox.replaceWith( '<input type="hidden" class="hidden" name="' + input_name + '" id="' + input_id + '" value="" placeholder="' + placeholder + '" />' );

$newstate = $( '<input type="hidden" />' )
.prop( 'id', input_id )
.prop( 'name', input_name )
.prop( 'placeholder', placeholder )
.addClass( 'hidden' );
$parent.hide().find( '.select2-container' ).remove();
$statebox.replaceWith( $newstate );
$( document.body ).trigger( 'country_to_state_changed', [ country, $wrapper ] );

} else {

var options = '',
state = states[ country ];

for( var index in state ) {
if ( state.hasOwnProperty( index ) ) {
options = options + '<option value="' + index + '">' + state[ index ] + '</option>';
}
}
var state = states[ country ],
$defaultOption = $( '<option value=""></option>' ).text( wc_country_select_params.i18n_select_state_text );

$statebox.closest( 'p.form-row' ).show();

if ( $statebox.is( 'input' ) ) {
// Change for select
$statebox.replaceWith( '<select name="' + input_name + '" id="' + input_id + '" class="state_select" data-placeholder="' + placeholder + '"></select>' );
$newstate = $( '<select></select>' )
.prop( 'id', input_id )
.prop( 'name', input_name )
.data( 'placeholder', placeholder )
.addClass( 'state_select' );
$statebox.replaceWith( $newstate );
$statebox = $wrapper.find( '#billing_state, #shipping_state, #calc_shipping_state' );
}

$statebox.html( '<option value="">' + wc_country_select_params.i18n_select_state_text + '</option>' + options );
$statebox.empty().append( $defaultOption );

$.each( state, function( index ) {
var $option = $( '<option></option>' )
.prop( 'value', index )
.text( state[ index ] );
$statebox.append( $option );
} );

$statebox.val( value ).change();

$( document.body ).trigger( 'country_to_state_changed', [country, $wrapper ] );

}
} else {
if ( $statebox.is( 'select' ) ) {

if ( $statebox.is( 'select, input[type="hidden"]' ) ) {
$newstate = $( '<input type="text" />' )
.prop( 'id', input_id )
.prop( 'name', input_name )
.prop( 'placeholder', placeholder )
.addClass( 'input-text' );
$parent.show().find( '.select2-container' ).remove();
$statebox.replaceWith( '<input type="text" class="input-text" name="' + input_name + '" id="' + input_id + '" placeholder="' + placeholder + '" />' );

$statebox.replaceWith( $newstate );
$( document.body ).trigger( 'country_to_state_changed', [country, $wrapper ] );

} else if ( $statebox.is( 'input[type="hidden"]' ) ) {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/frontend/country-select.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.