Make WordPress Core

Ticket #16859: 16859-03.2.patch

File 16859-03.2.patch, 3.8 KB (added by gcorne, 11 years ago)
  • src/wp-includes/formatting.php

    diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
    index 8b5f3f8..2892c42 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 ( ! $components ) {
     2896                return  '';
     2897        }
     2898
     2899        // not sure why we are including \x80 - \xa0, but also am not sure how well the byte sequences will work with
     2900        // UTF-8 characters since
     2901        $allowed_chars = 'a-z0-9-~+_.!$&\'()*+,;=%\\x80-\\xff';
     2902       
     2903        foreach( $components as $component => $val ) {
     2904                $regex = false;
     2905                $encode_brackets = false;
     2906
     2907                switch( $component ) {
     2908                        case 'host':
     2909                                $regex = '|[^' . $allowed_chars . '%:\[\]]|i';
     2910                        break;
     2911                        case 'path':
     2912                                $encode_brackets = true;
     2913                                $regex = '|[^' . $allowed_chars .  '%/:@]|i';
     2914                                break;
     2915                        case 'query':
     2916                                $encode_brackets = true;
     2917                                $regex = '|[^' . $allowed_chars . '%/:@?|i';
     2918                        case 'fragment':
     2919                                $encode_brackets = true;
     2920                                $regex = '|[^' . $allowed_chars . '%/:@?]|i';
     2921                                break;
     2922                        case 'scheme':
     2923                        case 'port':
     2924                        case 'user':
     2925                        case 'pass':
     2926                                break;
     2927                }
     2928
     2929                if ( $encode_brackets ) {
     2930                        $components[ $component ] = str_replace( '[', '%5B', $components[ $component ] );
     2931                        $components[ $component ] = str_replace( ']', '%5D', $components[ $component ] );
     2932                }
     2933
     2934                if ( $regex ) {
     2935                        $components[ $component ] = preg_replace( $regex, '', $components[ $component ] );
     2936                }
     2937
     2938        }
     2939
     2940        $url = '';
     2941
     2942        if ( isset( $components['scheme'] ) ) {
     2943                $url .= $components['scheme'] . ':';
     2944        }
     2945
     2946        if ( isset( $components['host'] ) )  {
     2947                $url .= '//' . $components['host'];
     2948        }
     2949
     2950        if ( isset( $components['path'] ) ) {
     2951                $url .= $components['path'];
     2952        }
     2953
     2954        if ( isset( $components['query'] ) ) {
     2955                $url .= '?' . $components['query'];
     2956        }
     2957
     2958        if ( isset( $components['fragment'] ) ) {
     2959                $url .= '#' . $components['fragment'];
     2960        } else if ( $original_url[ strlen( $original_url ) - 1 ] === '#' ) {
     2961                $url .= '#';
     2962        }
    28842963
    28852964        // Replace ampersands and single quotes only when displaying.
    28862965        if ( 'display' == $_context ) {