Cleans a passed URL.

@param  String  url An HTTP URL
@return String
484866
function cleanUrl(url) {
    "use strict";
    if (url.toLowerCase().indexOf('http') !== 0) {
        return url;
    }
    var a = document.createElement('a');
    a.href = url;
    return a.href;
}
806890
def _clean_url(self, url):
        
        # TODO: Turn this into regex
        if not url.startswith('http') or url.endswith('}}') or 'nojs_router' in url:
            return None
        if site(norm(url).lower()) in config.NONCANONIC_SITES:
            clean_url = canonicalize_url(url, keep_params=True)
        else:
            clean_url = canonicalize_url(url)
        return clean_url
571058
def clean_url(url)
      uri = URI.parse(url)
      uri.query = CGI.parse(uri.query || '').reject { |k| k == 'api_key' }.to_query
      uri.to_s
    end
1203059
private static String normalize(String url) {
        if (StringUtils.isBlank(url)) {
            return null;
        }
        // Strip "/tree/..."
        if (url.contains("/tree/")) {
            url = url.replaceFirst("/tree/.*$", "");
        }
        if (!url.endsWith("/")) {
            url += '/';
        }
        return url;
    }
877493
protected function cleanUrl($url)
    {
        $parts = parse_url($url);
        $fragment = empty($parts['fragment']) ? '' : '#'.$parts['fragment'];
        $path = empty($parts['path']) ? '/' : $parts['path'];

        return preg_replace('/^\/[^\.\/]+\.php\//', '/', $path).$fragment;
    }
290305
public function prepareURLForPersist($url)
    {
        if (substr($url, 0, 7 ) == "http://") return $url;

        if (substr($url, 0, 8 ) == "https://") return $url;

        $washedUrl  = "http://";
        $washedUrl .= $url;

        return $url;
    }
393620
private function removeTrailingSlash($url)
    {
        // if there is a final slash, we take the URL without this slash (expected URL format)
        if (strlen($url) > 5
            && $url[strlen($url) - 1] == '/'
        ) {
            $url = substr($url, 0, strlen($url) - 1);
        }

        return $url;
    }
720206
protected function cleanPath($uri)
    {
        $urlPath = parse_url($uri, PHP_URL_PATH);
        $uri     = str_replace('v1/', '', $urlPath);
        $path    = preg_replace('/(\/\w{10}$|self|\d*)/', '', $uri);
        return trim(preg_replace('/\/{1,2}|\-/', '_', $path), '_');
    }
383385
protected static String cleanupUrl(final String url) {
        if (url == null) {
            return null;
        }
        val jsessionPosition = url.indexOf(";jsession");
        if (jsessionPosition == -1) {
            return url;
        }
        val questionMarkPosition = url.indexOf('?');
        if (questionMarkPosition < jsessionPosition) {
            return url.substring(0, url.indexOf(";jsession"));
        }
        return url.substring(0, jsessionPosition) + url.substring(questionMarkPosition);
    }
674495
public static function fixUri($url) {
        $url = preg_replace('#/+|\\\+#', '/', $url);

        if ($url[0] == '/') {
            $url = substr($url, 1, strlen($url));
        } if (substr($url, -1) == '/') {
            $url = substr($url, 0, strlen($url) - 1);
        }

        return $url;
    }
528470
protected function clean_url($value) {
        global $CFG;

        if (empty($value)) {
            // Nothing.

        } else if (strpos($value, $CFG->wwwroot . '/') === 0) {
            $value = str_replace($CFG->wwwroot, '', $value);

        } else if (strpos($value, '/') !== 0) {
            debugging("Invalid url_select urls parameter: url '$value' is not local relative url!", DEBUG_DEVELOPER);
        }

        return $value;
    }
59109
public static function removeQueryString($url) {
        $pos = strpos($url, '?');
        if ( $pos === false ) return $url;
        $url = substr($url,0,$pos);
        return $url;
    }
1227713
public function purgeUrl ($url = null)
    {
        $apiKey = $this->settings->apiKey;

        Craft::trace(
            Craft::t(
                'imgix',
                'Purging asset: {url}', [ 'url' => $url ]
            ),
            'imgix');

        try {
            $client = Craft::createGuzzleClient([ 'timeout' => 30, 'connect_timeout' => 30 ]);

            $response = $client->post(self::IMGIX_PURGE_ENDPOINT, [
                'auth'        => [
                    $apiKey, ''
                ],
                'form_params' => [
                    'url' => $url,
                ]
            ]);

            Craft::trace(
                Craft::t(
                    'imgix',
                    'Purged asset: {url} - Status code {statusCode}', [
                        'url'        => $url,
                        'statusCode' => $response->getStatusCode()
                    ]
                ),
                'imgix');

            return $response->getStatusCode() >= 200 && $response->getStatusCode() < 400;
        }
        catch (RequestException $e) {
            Craft::error(
                Craft::t(
                    'imgix',
                    'Failed to purge {url}: {statusCode} {error}', [
                        'url'        => $url,
                        'error'      => $e->getMessage(),
                        'statusCode' => $e->getResponse()->getStatusCode() ]
                ),
                'imgix'
            );

            return false;
        }
    }
967625
public static function segmentizeUrl($url)
        {
            $url = self::normalizeUrl($url);
            $segments = explode('/', $url);

            $result = array();

            foreach ($segments as $segment) {
                if (strlen($segment)) $result[] = $segment;
            }

            return $result;
        }
1082149
public static function segmentUrl($url = null)
    {
        if (!is_null($url) && !empty($url)) {
            $url = $url;
        } else {
            $url = self::requestInstance()->getRequestUrl();
        }

        return explode('/', trim($url, '/'));
    }
224944
private function clean($string) {
	   $string = str_replace(' ', '', $string);
	   $string = str_replace('-', '', $string);
	   return preg_replace('/[^A-Za-z0-9\-]/', '', $string);
	}
1132487
protected function _fixUrlForParsing($url)
    {
        $path = $url->path;

        //bug in request
        if ($url->format == 'php') {
            $path .= '.php';
            $url->format = null;
        }

        $path = substr_replace($path, '', 0, strlen($this->_base_url->path));
        $path = preg_replace('/index\/?.php/', '', $path);
        $path = trim($path, '/');

        $url->path = $path;
        $url->format = $url->format ? $url->format : pick(AnRequest::format(), 'html');

        if (! empty($url->format)) {
            $url->query['format'] = $url->format;
        }
    }