Ticket #11608: 11608.2.diff
File 11608.2.diff, 1.7 KB (added by , 15 years ago) |
---|
-
wp-db.php
533 533 * Prepares a SQL query for safe execution. Uses sprintf()-like syntax. 534 534 * 535 535 * This function only supports a small subset of the sprintf syntax; it only supports %d (decimal number), %s (string). 536 * All % characters inside $query string literals, including LIKE wildcards, must be double %-escaped as %%. 537 * 536 538 * Does not support sign, padding, alignment, width or precision specifiers. 537 539 * Does not support argument numbering/swapping. 538 540 * … … 541 543 * Both %d and %s should be left unquoted in the query string. 542 544 * 543 545 * <code> 544 * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", "foo", 1337 ) 546 * $wpdb->prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", "foo", 1337 ); 547 * $wpdb->prepare( "UPDATE $wpdb->posts SET guid = '100%% Satisfied' WHERE ID = %s", $stringin ); 545 548 * </code> 546 549 * 550 * Care must be taken not to allow direct user input to the second param, which enables array manipulation. 551 * 547 552 * @link http://php.net/sprintf Description of syntax. 548 553 * @since 2.3.0 549 554 * … … 562 567 $args = $args[0]; 563 568 $query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it 564 569 $query = str_replace('"%s"', '%s', $query); // doublequote unquoting 565 $query = str_replace('%s', "'%s'", $query); // quote thestrings570 $query = preg_replace('|(?<!%)%s|', "'%s'", $query); //quote the strings, Avoiding escaped strings 566 571 array_walk($args, array(&$this, 'escape_by_ref')); 567 572 return @vsprintf($query, $args); 568 573 }