Make WordPress Core

Changeset 33310

Timestamp:
07/17/2015 07:06:33 AM (9 years ago)
Author:
pento
Message:

WPDB: ::strip_text_from_query() doesn't pass a length to ::strip_invalid_text(), which was causing queries to fail when they contained characters that needed to be sanity checked by MySQL.

Props dd32, mdawaffe, pento.

Fixes #32279.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/wp-db.php

    r33308 r33310  
    26302630            if ( is_array( $value['length'] ) ) {
    26312631                $length = $value['length']['length'];
     2632
    26322633            } else {
    26332634                $length = false;
     2635
     2636
     2637
     2638
    26342639            }
    26352640
     
    26432648                continue;
    26442649            }
    2645 
    2646             $truncate_by_byte_length = 'byte' === $value['length']['type'];
    26472650
    26482651            $needs_validation = true;
     
    27192722                    }
    27202723
    2721                     $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING {$this->charset} )", $value['value'], $value['length']['length'] );
     2724                    if ( is_array( $value['length'] ) ) {
     2725                        $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING {$this->charset} )", $value['value'], $value['length']['length'] );
     2726                    } else if ( 'binary' !== $charset ) {
     2727                        // If we don't have a length, there's no need to convert binary - it will always return the same result.
     2728                        $queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING {$this->charset} )", $value['value'] );
     2729                    }
    27222730
    27232731                    unset( $data[ $col ]['db'] );
  • trunk/tests/phpunit/tests/db/charset.php

    r33308 r33310  
    214214                'expected' => "\xd8ord\xd0ress",
    215215                'length'   => array( 'type' => 'char', 'length' => 100 ),
     216
     217
     218
     219
     220
     221
     222
     223
     224
     225
     226
     227
     228
     229
     230
    216231            ),
    217232            'cp1251_char_length' => array(
     
    808823        $this->assertEquals( 255, strlen( $stripped ) );
    809824    }
     825
     826
     827
     828
     829
     830
     831
     832
     833
     834
     835
     836
     837
     838
     839
     840
     841
    810842}
Note: See TracChangeset for help on using the changeset viewer.