Aleksander Machniak
2014-09-13 848e204ef9bdaf989e7e48025d4ea6ee21e7678e
program/lib/Roundcube/rcube_utils.php
@@ -103,13 +103,14 @@
            }
            foreach ($domain_array as $part) {
                if (!preg_match('/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]))$/', $part)) {
                if (!preg_match('/^((xn--)?([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]))$/', $part)) {
                    return false;
                }
            }
            // last domain part
            if (preg_match('/[^a-zA-Z]/', array_pop($domain_array))) {
            $last_part = array_pop($domain_array);
            if (strpos($last_part, 'xn--') !== 0 && preg_match('/[^a-zA-Z]/', $last_part)) {
                return false;
            }
@@ -1068,7 +1069,37 @@
            return (bool) preg_match('!^[a-z]:[\\\\/]!i', $path);
        }
        else {
            return $path[0] == DIRECTORY_SEPARATOR;
            return $path[0] == '/';
        }
    }
    /**
     * Resolve relative URL
     *
     * @param string $url Relative URL
     *
     * @return string Absolute URL
     */
    public static function resolve_url($url)
    {
        // prepend protocol://hostname:port
        if (!preg_match('|^https?://|', $url)) {
            $schema       = 'http';
            $default_port = 80;
            if (self::https_check()) {
                $schema       = 'https';
                $default_port = 443;
            }
            $prefix = $schema . '://' . preg_replace('/:\d+$/', '', $_SERVER['HTTP_HOST']);
            if ($_SERVER['SERVER_PORT'] != $default_port) {
                $prefix .= ':' . $_SERVER['SERVER_PORT'];
            }
            $url = $prefix . ($url[0] == '/' ? '' : '/') . $url;
        }
        return $url;
    }
}