wp_validate_redirect

The timeline below displays how wordpress function wp_validate_redirect has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $fallback_url supplied.
 *
 * @since 2.8.1
 *
 * @param string $location     The redirect to validate.
 * @param string $fallback_url The value to return if $location is not allowed.
 * @return string Redirect-sanitized URL.
 */
function wp_validate_redirect($location, $fallback_url = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if (str_starts_with($location, '//')) {
        $location = 'http:' . $location;
    }
    /*
     * In PHP 5 parse_url() may fail if the URL query part contains 'http://'.
     * See https://bugs.php.net/bug.php?id=38143
     */
    $cut = strpos($location, '?');
    $test = $cut ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL.
    if (false === $lp) {
        return $fallback_url;
    }
    // Allow only 'http' and 'https' schemes. No 'data:', etc.
    if (isset($lp['scheme']) && !('http' === $lp['scheme'] || 'https' === $lp['scheme'])) {
        return $fallback_url;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    /*
     * Reject if certain components are set but host is not.
     * This catches URLs like https:host.com for which parse_url() does not set the host field.
     */
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $fallback_url;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $fallback_url;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the list of allowed hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param string[] $hosts An array of allowed host names.
     * @param string   $host  The host name of the redirect destination; empty string if not set.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts, true) && strtolower($wpp['host']) !== $lp['host'])) {
        $location = $fallback_url;
    }
    return $location;
}

WordPress Version: 6.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $fallback_url supplied.
 *
 * @since 2.8.1
 *
 * @param string $location     The redirect to validate.
 * @param string $fallback_url The value to return if $location is not allowed.
 * @return string Redirect-sanitized URL.
 */
function wp_validate_redirect($location, $fallback_url = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if ('//' === substr($location, 0, 2)) {
        $location = 'http:' . $location;
    }
    // In PHP 5 parse_url() may fail if the URL query part contains 'http://'.
    // See https://bugs.php.net/bug.php?id=38143
    $cut = strpos($location, '?');
    $test = $cut ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL.
    if (false === $lp) {
        return $fallback_url;
    }
    // Allow only 'http' and 'https' schemes. No 'data:', etc.
    if (isset($lp['scheme']) && !('http' === $lp['scheme'] || 'https' === $lp['scheme'])) {
        return $fallback_url;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not.
    // This catches URLs like https:host.com for which parse_url() does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $fallback_url;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $fallback_url;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the list of allowed hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param string[] $hosts An array of allowed host names.
     * @param string   $host  The host name of the redirect destination; empty string if not set.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts, true) && strtolower($wpp['host']) !== $lp['host'])) {
        $location = $fallback_url;
    }
    return $location;
}

WordPress Version: 6.1

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied.
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate.
 * @param string $default  The value to return if $location is not allowed.
 * @return string redirect-sanitized URL.
 */
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if ('//' === substr($location, 0, 2)) {
        $location = 'http:' . $location;
    }
    // In PHP 5 parse_url() may fail if the URL query part contains 'http://'.
    // See https://bugs.php.net/bug.php?id=38143
    $cut = strpos($location, '?');
    $test = $cut ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL.
    if (false === $lp) {
        return $default;
    }
    // Allow only 'http' and 'https' schemes. No 'data:', etc.
    if (isset($lp['scheme']) && !('http' === $lp['scheme'] || 'https' === $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not.
    // This catches URLs like https:host.com for which parse_url() does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the list of allowed hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param string[] $hosts An array of allowed host names.
     * @param string   $host  The host name of the redirect destination; empty string if not set.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts, true) && strtolower($wpp['host']) !== $lp['host'])) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 5.5

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if ('//' === substr($location, 0, 2)) {
        $location = 'http:' . $location;
    }
    // In PHP 5 parse_url() may fail if the URL query part contains 'http://'.
    // See https://bugs.php.net/bug.php?id=38143
    $cut = strpos($location, '?');
    $test = $cut ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL.
    if (false === $lp) {
        return $default;
    }
    // Allow only 'http' and 'https' schemes. No 'data:', etc.
    if (isset($lp['scheme']) && !('http' === $lp['scheme'] || 'https' === $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not.
    // This catches URLs like https:host.com for which parse_url() does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the list of allowed hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param string[] $hosts An array of allowed host names.
     * @param string   $host  The host name of the redirect destination; empty string if not set.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts, true) && strtolower($wpp['host']) !== $lp['host'])) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In PHP 5 parse_url() may fail if the URL query part contains 'http://'.
    // See https://bugs.php.net/bug.php?id=38143
    $cut = strpos($location, '?');
    $test = $cut ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL.
    if (false === $lp) {
        return $default;
    }
    // Allow only 'http' and 'https' schemes. No 'data:', etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not.
    // This catches URLs like https:host.com for which parse_url() does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param string[] $hosts An array of allowed host names.
     * @param string   $host  The host name of the redirect destination; empty string if not set.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && strtolower($wpp['host']) !== $lp['host'])) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 5.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In PHP 5 parse_url() may fail if the URL query part contains 'http://'.
    // See https://bugs.php.net/bug.php?id=38143
    $cut = strpos($location, '?');
    $test = $cut ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL.
    if (false === $lp) {
        return $default;
    }
    // Allow only 'http' and 'https' schemes. No 'data:', etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not.
    // This catches URLs like https:host.com for which parse_url() does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param string[] $hosts An array of allowed host names.
     * @param string   $host  The host name of the redirect destination; empty string if not set.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && strtolower($wpp['host']) !== $lp['host'])) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 3.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if ('//' === substr($location, 0, 2)) {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $cut = strpos($location, '?');
    $test = $cut ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 3.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $cut = strpos($location, '?');
    $test = $cut ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if ('//' === substr($location, 0, 2)) {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $cut = strpos($location, '?');
    $test = $cut ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 5.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $cut = strpos($location, '?');
    $test = $cut ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 2.7

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if ('//' === substr($location, 0, 2)) {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 2.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 2.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .20

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if ('//' === substr($location, 0, 2)) {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 2.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if ('//' === substr($location, 0, 2)) {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
            $path = wp_normalize_path($path);
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 5.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 1.6

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if ('//' === substr($location, 0, 2)) {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 1.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    if ('//' === substr($location, 0, 2)) {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 5.1

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 */
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 0.6

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 0.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .20

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 0.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 9.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .20

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 9.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .15

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .11

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 8.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 7.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 4.7

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 6.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 6.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .20

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 6.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .19

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .15

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 4.6

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filters the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 5.7

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 5.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .30

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 5.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .22

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .20

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 5.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .18

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 4.5

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 4.8

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 4.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .30

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 4.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .23

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .20

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 4.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .19

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 4.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 3.9

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 3.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .30

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 3.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .24

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .20

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 3.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 4.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default  The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 2.7

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 2.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .30

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 2.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .28

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .24

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .20

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 2.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .13

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 1.5

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .40

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 1.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .31

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .30

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 1.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .27

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .20

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 1.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .16

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 0.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .31

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .30

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 0.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .27

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .20

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 0.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .16

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .10

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 9.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .11

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 3.9

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    /**
     * Filter the whitelist of hosts to redirect to.
     *
     * @since 2.3.0
     *
     * @param array       $hosts An array of allowed hosts.
     * @param bool|string $host  The parsed host; empty if not isset.
     */
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 8.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .34

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .30

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 8.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .20

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 8.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .19

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .13

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 7.5

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .40

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 7.4

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .34

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = wp_sanitize_redirect(trim($location, " \t\n\r\x00\x08\v"));
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .30

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    if (!isset($lp['host']) && !empty($lp['path']) && '/' !== $lp['path'][0]) {
        $path = '';
        if (!empty($_SERVER['REQUEST_URI'])) {
            $path = dirname(parse_url('http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?');
        }
        $location = '/' . ltrim($path . '/', '/') . $location;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 7.3

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .20

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 7.2

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .19

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location, " \t\n\r\x00\x08\v");
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: .13

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
    $lp = @parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (!isset($lp['host']) && (isset($lp['scheme']) || isset($lp['user']) || isset($lp['pass']) || isset($lp['port']))) {
        return $default;
    }
    // Reject malformed components parse_url() can return on odd inputs.
    foreach (array('user', 'pass', 'host') as $component) {
        if (isset($lp[$component]) && strpbrk($lp[$component], ':/?#@')) {
            return $default;
        }
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}

WordPress Version: 3.7

/**
 * Validates a URL for use in a redirect.
 *
 * Checks whether the $location is using an allowed host, if it has an absolute
 * path. A plugin can therefore set or remove allowed host(s) to or from the
 * list.
 *
 * If the host is not allowed, then the redirect is to $default supplied
 *
 * @since 2.8.1
 * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
 *		WordPress host string and $location host string.
 *
 * @param string $location The redirect to validate
 * @param string $default The value to return if $location is not allowed
 * @return string redirect-sanitized URL
 **/
function wp_validate_redirect($location, $default = '')
{
    $location = trim($location);
    // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
    if (substr($location, 0, 2) == '//') {
        $location = 'http:' . $location;
    }
    // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
    $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location;
    $lp = parse_url($test);
    // Give up if malformed URL
    if (false === $lp) {
        return $default;
    }
    // Allow only http and https schemes. No data:, etc.
    if (isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme'])) {
        return $default;
    }
    // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    if (isset($lp['scheme']) && !isset($lp['host'])) {
        return $default;
    }
    $wpp = parse_url(home_url());
    $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
    if (isset($lp['host']) && (!in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) {
        $location = $default;
    }
    return $location;
}