WordPress.org

Make WordPress Core

Ticket #41482: 41482.patch

File 41482.patch, 3.8 KB (added by umangvaghela123, 3 years ago)
  • src/wp-includes/formatting.php

     
    29602960        /** This filter is documented in wp-includes/formatting.php */
    29612961        return apply_filters( 'is_email', $email, $email, null );
    29622962}
     2963/**
     2964 * Verifies url is valid as wordpress site url
     2965 * The regex check just if th protocol are http o https.
     2966 * In case other protocol are need to be considered valid, one has to edit the regex through the filter
     2967 *
     2968 * @param string $url Url address to verify.
     2969 *
     2970 * @return bool            False if it is not a valid wordpress site url
     2971 */
     2972function is_url( $url ) {
    29632973
     2974        $valid_url_pattern = '~^
     2975                            (http(s)?)://                           # protocol
     2976                            (([\pL\pN-]+:)?([\pL\pN-]+)@)?          # basic auth
     2977                            (
     2978                                ([\pL\pN\pS-\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
     2979                                    |                                                 # or
     2980                                \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}                    # an IP address
     2981                                    |                                                 # or
     2982                                \[
     2983                                    (?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(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?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))
     2984                                \]  # an IPv6 address
     2985                            )
     2986                            (:[0-9]+)?                              # a port (optional)
     2987                            (?:/ (?:[\pL\pN\-._\~!$&\'()*+,;=:@]|%%[0-9A-Fa-f]{2})* )*      # a path
     2988                        $~ixu';
     2989
     2990        /**
     2991         * basic check before running the regex
     2992         */
     2993        if ( empty( trim( $url ) ) ) {
     2994                return false;
     2995        }
     2996
     2997        /**
     2998         * Filters to edit the regex pattern for a valid url
     2999         *
     3000         * @param string $valid_url_pattern The regex pattern to valid url against
     3001         */
     3002        $valid_url_pattern = apply_filters( 'valid_url_pattern', $valid_url_pattern );
     3003
     3004        if ( ! preg_match( $valid_url_pattern, $url ) ) {
     3005
     3006                //is not a valid url
     3007                return false;
     3008        } else {
     3009
     3010                //is valid url
     3011                return true;
     3012        }
     3013}
    29643014/**
    29653015 * Convert to ASCII from email subjects.
    29663016 *