Make WordPress Core


Ignore:
Timestamp:
09/19/2017 05:55:33 PM (7 years ago)
Author:
aaroncampbell
Message:

Database: Hardening to bring wpdb::prepare() inline with documentation.

wpdb::prepare() supports %s, %d, and %F as placeholders in the query string. Any other non-escaped % will be escaped.

File:
1 edited

Legend:

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

    r41483 r41496  
    12531253        $query = preg_replace( '|(?<!%)%f|' , '%F', $query ); // Force floats to be locale unaware
    12541254        $query = preg_replace( '|(?<!%)%s|', "'%s'", $query ); // quote the strings, avoiding escaped strings like %%s
     1255        $query = preg_replace( '/%(?:%|$|([^dsF]))/', '%%\\1', $query ); // escape any unescaped percents
    12551256        array_walk( $args, array( $this, 'escape_by_ref' ) );
    12561257        return @vsprintf( $query, $args );
     
    28222823
    28232824                    if ( is_array( $value['length'] ) ) {
    2824                         $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING $connection_charset )", $value['value'], $value['length']['length'] );
     2825                        $length = sprintf( '%.0f', $value['length']['length'] );
     2826                        $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), $length ) USING $connection_charset )", $value['value'] );
    28252827                    } else if ( 'binary' !== $charset ) {
    28262828                        // If we don't have a length, there's no need to convert binary - it will always return the same result.
Note: See TracChangeset for help on using the changeset viewer.