Make WordPress Core

Ticket #16859: 16859-03.patch

File 16859-03.patch, 3.5 KB (added by gcorne, 12 years ago)
  • src/wp-includes/formatting.php

    diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
    index 8b5f3f8..93a2c1d 100644
    function _make_web_ftp_clickable_cb($matches) { 
    16631663        $ret = '';
    16641664        $dest = $matches[2];
    16651665        $dest = 'http://' . $dest;
    1666         $dest = esc_url($dest);
    1667         if ( empty($dest) )
    1668                 return $matches[0];
    16691666
    16701667        // removed trailing [.,;:)] from URL
    16711668        if ( in_array( substr($dest, -1), array('.', ',', ';', ':', ')') ) === true ) {
    16721669                $ret = substr($dest, -1);
    16731670                $dest = substr($dest, 0, strlen($dest)-1);
    16741671        }
     1672
     1673        $dest = esc_url($dest);
     1674        if ( empty($dest) )
     1675                return $matches[0];
     1676
    16751677        return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>$ret";
    16761678}
    16771679
    function esc_sql( $data ) { 
    28552857 * (the default behaviour) ampersands are also replaced. The 'clean_url' filter
    28562858 * is applied to the returned cleaned URL.
    28572859 *
     2860 * See RFC3986
     2861 *
    28582862 * @since 2.8.0
    28592863 * @uses wp_kses_bad_protocol() To only permit protocols in the URL set
    28602864 *              via $protocols or the common ones set in the function.
    function esc_url( $url, $protocols = null, $_context = 'display' ) { 
    28702874
    28712875        if ( '' == $url )
    28722876                return $url;
    2873         $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url);
    2874         $strip = array('%0d', '%0a', '%0D', '%0A');
    2875         $url = _deep_replace($strip, $url);
     2877
     2878
    28762879        $url = str_replace(';//', '://', $url);
     2880
    28772881        /* If the URL doesn't appear to contain a scheme, we
    2878          * presume it needs http:// appended (unless a relative
     2882         * presume it needs http:// prepended (unless a relative
    28792883         * link starting with /, # or ? or a php file).
    28802884         */
    28812885        if ( strpos($url, ':') === false && ! in_array( $url[0], array( '/', '#', '?' ) ) &&
    2882                 ! preg_match('/^[a-z0-9-]+?\.php/i', $url) )
    2883                 $url = 'http://' . $url;
     2886                ! preg_match('/^[a-z0-9-]+?\.php/i', $url) ) {
     2887                        $url = 'http://' . $url;
     2888        }
     2889
     2890        $strip = array('%0d', '%0a', '%0D', '%0A');
     2891        $url = _deep_replace($strip, $url);
     2892
     2893        $components = @parse_url( $url );
     2894
     2895        if ( $url[ strlen( $url ) - 1 ] === ':' ) {
     2896                var_dump( $components );
     2897        }
     2898        if ( ! $components ) {
     2899                return  '';
     2900        }
     2901
     2902        // not sure why we are including \x80 - \xa0, but also am not sure how well the byte sequences will work with
     2903        // UTF-8 characters since
     2904        $allowed_chars = 'a-z0-9-~+_.!$&\'()*+,;=%\\x80-\\xff';
     2905       
     2906        foreach( $components as $component => $val ) {
     2907                $regex = false;
     2908
     2909                switch( $component ) {
     2910                        case 'host':
     2911                                $regex = '|[^' . $allowed_chars . '%:\[\]]|i';
     2912                        break;
     2913                        case 'path':
     2914                                $regex = '|[^' . $allowed_chars .  '%/:@]|i';
     2915                                break;
     2916                        case 'query':
     2917                                $regex = '|[^' . $allowed_chars . '%/:@?|i';
     2918                        case 'fragment':
     2919                                $regex = '|[^' . $allowed_chars . '%/:@?]|i';
     2920                                break;
     2921                        case 'scheme':
     2922                        case 'port':
     2923                        case 'user':
     2924                        case 'pass':
     2925                                break;
     2926                }
     2927
     2928                if ( $regex ) {
     2929                        $components[ $component ] = preg_replace( $regex, '', $components[ $component ] );
     2930                }
     2931        }
     2932
     2933        $url = '';
     2934
     2935        if ( isset( $components['scheme'] ) ) {
     2936                $url .= $components['scheme'] . ':';
     2937        }
     2938
     2939        if ( isset( $components['host'] ) )  {
     2940                $url .= '//' . $components['host'];
     2941        }
     2942
     2943        if ( isset( $components['path'] ) ) {
     2944                $url .= $components['path'];
     2945        }
     2946
     2947        if ( isset( $components['query'] ) ) {
     2948                $url .= '?' . $components['query'];
     2949        }
     2950
     2951        if ( isset( $components['fragment'] ) ) {
     2952                $url .= '#' . $components['fragment'];
     2953        } else if ( $original_url[ strlen( $original_url ) - 1 ] === '#' ) {
     2954                $url .= '#';
     2955        }
    28842956
    28852957        // Replace ampersands and single quotes only when displaying.
    28862958        if ( 'display' == $_context ) {