Ticket #11608: 11608.patch

File 11608.patch, 3.2 KB (added by hakre, 3 years ago)

Unneded code (by definition) moved out, compacted the initial docblock and added a note that this has nothing to do with prepared statements.

  • wp-includes/wp-db.php

    ### Eclipse Workspace Patch 1.0
    #P wordpress-trunk
     
    530530        } 
    531531 
    532532        /** 
    533          * Prepares a SQL query for safe execution.  Uses sprintf()-like syntax. 
     533         * Mimicks a prepare of a SQL query for execution.   
     534         *  
     535         * The following placeholders can be used for values: 
     536         *  
     537         *   %d (decimal number) 
     538         *   %s (string) 
     539         *   %% (%) 
     540         *    
     541         * Both %d and %s should be left unquoted in the query string. 
    534542         * 
     543         * <code> 
     544         * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", "foo", 1337 ) 
     545         * </code> 
     546         *  
     547         * NOTE: This has nothing to do with prepared statements your database might support. 
     548         *   
     549         * More technical information: 
     550         *  
     551         * Uses sprintf()-like syntax. 
     552         * 
    535553         * This function only supports a small subset of the sprintf syntax; it only supports %d (decimal number), %s (string). 
    536554         * Does not support sign, padding, alignment, width or precision specifiers. 
    537555         * Does not support argument numbering/swapping. 
    538556         * 
    539557         * May be called like {@link http://php.net/sprintf sprintf()} or like {@link http://php.net/vsprintf vsprintf()}. 
    540558         * 
    541          * Both %d and %s should be left unquoted in the query string. 
    542          * 
    543          * <code> 
    544          * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", "foo", 1337 ) 
    545          * </code> 
    546          * 
    547559         * @link http://php.net/sprintf Description of syntax. 
    548560         * @since 2.3.0 
    549561         * 
    550          * @param string $query Query statement with sprintf()-like placeholders 
    551          * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called like {@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}. 
    552          * @param mixed $args,... further variables to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}. 
     562         * @param string $query Query statement with wpdb->prepare placeholders 
     563         * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called compareable to {@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}. 
     564         * @param mixed $args,... further variables to substitute. 
    553565         * @return null|string Sanitized query string 
    554566         */ 
    555567        function prepare($query = null) { // ( $query, *$args ) 
     
    560572                // If args were passed as an array (as in vsprintf), move them up 
    561573                if ( isset($args[0]) && is_array($args[0]) ) 
    562574                        $args = $args[0]; 
    563                 $query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it 
    564                 $query = str_replace('"%s"', '%s', $query); // doublequote unquoting 
    565                 $query = str_replace('%s', "'%s'", $query); // quote the strings 
     575                $query = preg_replace('|(?<!%)%s|', "'%s'", $query); //quote the strings, Avoiding escaped strings 
    566576                array_walk($args, array(&$this, 'escape_by_ref')); 
    567577                return @vsprintf($query, $args); 
    568578        }