Changeset 41496
- Timestamp:
- 09/19/2017 05:55:33 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/wp-db.php
r41483 r41496 1253 1253 $query = preg_replace( '|(?<!%)%f|' , '%F', $query ); // Force floats to be locale unaware 1254 1254 $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 1255 1256 array_walk( $args, array( $this, 'escape_by_ref' ) ); 1256 1257 return @vsprintf( $query, $args ); … … 2822 2823 2823 2824 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'] ); 2825 2827 } else if ( 'binary' !== $charset ) { 2826 2828 // If we don't have a length, there's no need to convert binary - it will always return the same result. -
trunk/tests/phpunit/tests/db.php
r41470 r41496 274 274 } 275 275 276 276 277 /** 277 278 * Test that SQL modes are set correctly … … 1116 1117 $this->assertSame( 'utf8_general_ci', $result['collate'] ); 1117 1118 } 1119 1120 /** 1121 * 1122 */ 1123 function test_prepare_with_unescaped_percents() { 1124 global $wpdb; 1125 1126 $sql = $wpdb->prepare( '%d %1$d %%% %', 1 ); 1127 $this->assertEquals( '1 %1$d %% %', $sql ); 1128 } 1118 1129 }
Note: See TracChangeset
for help on using the changeset viewer.