Merge pull request #23535 from woocommerce/fix/23518
Fix: parameter values should be converted back as well when building form fields
This commit is contained in:
commit
d2c7d8c86e
|
@ -705,7 +705,7 @@ function wc_query_string_form_fields( $values = null, $exclude = array(), $curre
|
||||||
$values = array();
|
$values = array();
|
||||||
|
|
||||||
if ( ! empty( $url_parts['query'] ) ) {
|
if ( ! empty( $url_parts['query'] ) ) {
|
||||||
// This is to preserve full-stops and spaces in the query string when ran through parse_str.
|
// This is to preserve full-stops, pluses and spaces in the query string when ran through parse_str.
|
||||||
$replace_chars = array(
|
$replace_chars = array(
|
||||||
'.' => '{dot}',
|
'.' => '{dot}',
|
||||||
'+' => '{plus}',
|
'+' => '{plus}',
|
||||||
|
@ -717,9 +717,11 @@ function wc_query_string_form_fields( $values = null, $exclude = array(), $curre
|
||||||
// Parse the string.
|
// Parse the string.
|
||||||
parse_str( $query_string, $parsed_query_string );
|
parse_str( $query_string, $parsed_query_string );
|
||||||
|
|
||||||
// Convert the full-stops back and add to values array.
|
// Convert the full-stops, pluses and spaces back and add to values array.
|
||||||
foreach ( $parsed_query_string as $key => $value ) {
|
foreach ( $parsed_query_string as $key => $value ) {
|
||||||
$values[ str_replace( array_values( $replace_chars ), array_keys( $replace_chars ), $key ) ] = $value;
|
$new_key = str_replace( array_values( $replace_chars ), array_keys( $replace_chars ), $key );
|
||||||
|
$new_value = str_replace( array_values( $replace_chars ), array_keys( $replace_chars ), $value );
|
||||||
|
$values[ $new_key ] = $new_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,22 +124,22 @@ class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
|
||||||
public function test_wc_query_string_form_fields() {
|
public function test_wc_query_string_form_fields() {
|
||||||
$actual_html = wc_query_string_form_fields( '?test=1', array(), '', true );
|
$actual_html = wc_query_string_form_fields( '?test=1', array(), '', true );
|
||||||
$expected_html = '<input type="hidden" name="test" value="1" />';
|
$expected_html = '<input type="hidden" name="test" value="1" />';
|
||||||
$this->assertEquals( $expected_html, $actual_html, var_export( $actual_html, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
|
$this->assertEquals( $expected_html, $actual_html );
|
||||||
|
|
||||||
$actual_html = wc_query_string_form_fields( '?test=1&test2=something', array(), '', true );
|
$actual_html = wc_query_string_form_fields( '?test=1&test2=something', array(), '', true );
|
||||||
$expected_html = '<input type="hidden" name="test" value="1" /><input type="hidden" name="test2" value="something" />';
|
$expected_html = '<input type="hidden" name="test" value="1" /><input type="hidden" name="test2" value="something" />';
|
||||||
$this->assertEquals( $expected_html, $actual_html, var_export( $actual_html, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
|
$this->assertEquals( $expected_html, $actual_html );
|
||||||
|
|
||||||
$actual_html = wc_query_string_form_fields( '?test.something=something', array(), '', true );
|
$actual_html = wc_query_string_form_fields( '?test.something=something.else', array(), '', true );
|
||||||
$expected_html = '<input type="hidden" name="test.something" value="something" />';
|
$expected_html = '<input type="hidden" name="test.something" value="something.else" />';
|
||||||
$this->assertEquals( $expected_html, $actual_html, var_export( $actual_html, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
|
$this->assertEquals( $expected_html, $actual_html );
|
||||||
|
|
||||||
$actual_html = wc_query_string_form_fields( '?test+something=something', array(), '', true );
|
$actual_html = wc_query_string_form_fields( '?test+something=something+else', array(), '', true );
|
||||||
$expected_html = '<input type="hidden" name="test+something" value="something" />';
|
$expected_html = '<input type="hidden" name="test+something" value="something+else" />';
|
||||||
$this->assertEquals( $expected_html, $actual_html, var_export( $actual_html, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
|
$this->assertEquals( $expected_html, $actual_html );
|
||||||
|
|
||||||
$actual_html = wc_query_string_form_fields( '?test%20something=something', array(), '', true );
|
$actual_html = wc_query_string_form_fields( '?test%20something=something%20else', array(), '', true );
|
||||||
$expected_html = '<input type="hidden" name="test%20something" value="something" />';
|
$expected_html = '<input type="hidden" name="test%20something" value="something%20else" />';
|
||||||
$this->assertEquals( $expected_html, $actual_html, var_export( $actual_html, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
|
$this->assertEquals( $expected_html, $actual_html );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue