Make WordPress Core

Ticket #30753: 30753.01.patch

File 30753.01.patch, 1.4 KB (added by r-a-y, 10 years ago)
  • src/wp-includes/formatting.php

     
    34633463 */
    34643464function wp_parse_str( $string, &$array ) {
    34653465        parse_str( $string, $array );
    3466         if ( get_magic_quotes_gpc() )
     3466        if ( get_magic_quotes_gpc() ) {
    34673467                $array = stripslashes_deep( $array );
     3468        }
     3469
     3470        // Cast strings of 'true' and 'false' as proper booleans
     3471        foreach( (array) $array as $key => $value ) {
     3472                if ( is_string( $value ) && ( 'true' === $value || 'false' === $value ) ) {
     3473                        $array[$key] = wp_validate_boolean( $value );
     3474                }
     3475        }
     3476
    34683477        /**
    34693478         * Filter the array of variables derived from a parsed string.
    34703479         *
  • new file tests/phpunit/tests/formatting/WPParseStr.php

    new file mode 100644
    - +  
     1<?php
     2
     3/**
     4 * @group formatting
     5 */
     6class Tests_Formatting_WPParseStr extends WP_UnitTestCase {
     7        public function test_querystring_values_as_booleans() {
     8                // when a querystring is used as the arg in wp_parse_args(), wp_parse_str() is used
     9                $r = wp_parse_args( 'this_should_be_bool_false=false&this_should_be_bool_true=true', array() );
     10
     11                $this->assertFalse( $r['this_should_be_bool_false'] );
     12                $this->assertTrue(  $r['this_should_be_bool_true'] );
     13        }
     14}