Some gems have 'http://github.com' as URI which will redirect to https
 leading `open_uri` to crash.

 @param url [String] the url to parse
 @return [URI] valid URI
965217
def correct_uri(url)
      return unless url.is_a?(String) && !url.empty?

      uri = URI(url)
      uri.scheme == 'http' ? known_https(uri) : uri
    end
319281
def urljoin_safe(base_url, url, allow_fragments=True):
    ''''''
    try:
        return wpull.url.urljoin(
            base_url, url, allow_fragments=allow_fragments
        )
    except ValueError as error:
        _logger.warning(__(
            _('Unable to parse URL ‘{url}’: {error}.'),
            url=url, error=error
        ))
1148001
def open_uri(uri, options, follows_remaining: 0)
      uri.open(options)
    rescue OpenURI::HTTPRedirect => exception
      raise Down::TooManyRedirects, "too many redirects" if follows_remaining == 0

      # fail if redirect URI scheme is not http or https
      begin
        uri = ensure_uri(exception.uri)
      rescue Down::InvalidUrl
        response = rebuild_response_from_open_uri_exception(exception)

        raise ResponseError.new("Invalid Redirect URI: #{exception.uri}", response: response)
      end

      # forward cookies on the redirect
      if !exception.io.meta["set-cookie"].to_s.empty?
        options["Cookie"] = exception.io.meta["set-cookie"]
      end

      follows_remaining -= 1
      retry
    rescue OpenURI::HTTPError => exception
      response = rebuild_response_from_open_uri_exception(exception)

      # open-uri attempts to parse the redirect URI, so we re-raise that exception
      if exception.message.include?("(Invalid Location URI)")
        raise ResponseError.new("Invalid Redirect URI: #{response["Location"]}", response: response)
      end

      response_error!(response)
    rescue => exception
      request_error!(exception)
    end
919121
def url(value):
    
    if not url_regex.search(value):
        message = u"{0} is not a valid URL".format(value)
        if url_regex.search('http://' + value):
            message += u". Did you mean: http://{0}".format(value)
        raise ValueError(message)
    return value
335892
def is_uri?(s)

      return false if s.index("\n")

      ((URI.parse(s); true) rescue false)
    end
305521
def parse_url(url):
    
    split_url = url.split('/', 3)
    if len(split_url) == 3:
        # http://foo.com
        path = '/'
    elif len(split_url) == 4:
        path = '/' + split_url[3]
    else:
        raise ValueError('Invalid URL: %s' % url)

    try:
        parse_result = urlparse(url)
    except Exception:
        raise ValueError('Invalid URL: %s' % url)

    protocol = parse_result.scheme
    protocol = protocol.lower()
    if protocol not in ('http', 'https'):
        raise ValueError('Invalid URL protocol "%s"' % protocol)

    split_netloc = parse_result.netloc.split(':')
    domain = split_netloc[0]
    domain = domain.lower()

    if len(split_netloc) == 2:
        try:
            port = int(split_netloc[1])
        except:
            raise ValueError('Invalid port: "%s"' % split_netloc[1])
    elif protocol == 'https':
        port = 443
    elif protocol == 'http':
        port = 80
    else:
        raise ValueError('Invalid scheme: "%s"' % protocol)

    return protocol, domain, port, path
437061
function getOwnerAndRepo(url) {
  let match = url.match(/^git@github\.com:(.*)\.git$/);
  match = match || url.match(/^git\+https:\/\/github\.com\/(.*)\.git$/);
  const gitUrlBase = match && match[1];
  return (gitUrlBase || url).split('/');
}
754933
def _parse_url_and_validate(cls, url):
        
        parsed_url = urlparse(url)
        if parsed_url.scheme and parsed_url.netloc:
            final_url = parsed_url.geturl()
        else:
            raise BadURLException
        return final_url
944242
def url(scheme: false)
      if scheme
        URI::Generic.build(scheme: type, host: addr, port: port).to_s
      else
        URI::Generic.build(host: addr, port: port).to_s
      end
    end
1365397
def guess_url_vcs(url):
    
    parsed = urllib.parse.urlsplit(url)

    if parsed.scheme in ('git', 'svn'):
        return parsed.scheme
    elif parsed.path.endswith('.git'):
        return 'git'
    elif parsed.hostname == 'github.com':
        return 'git'

    # If it's an http url, we can try requesting it and guessing from the
    # contents.
    if parsed.scheme in ('http', 'https'):
        resp = requests.get(url)
        if re.match('basehttp.*python.*', resp.headers.get('server').lower()):
            # It's the mercurial http server
            return 'hg'
    return None
616278
def connection_url_to_hash(url)
      url ||= ''
      uri = URI.parse url
      spec = {
        host:     uri.host,
        port:     uri.port,
        adapter:  uri.scheme,
        username: uri.user,
        password: uri.password,
        database: uri.path.sub(%r{^/}, '')
      }
      spec.reject! {|_, value| !value}
      {adapter: 'redis'}.merge spec
    end
59728
def _slug_from_url(url):
    
    http_match = _HTTPS_REGEX.match(url)
    ssh_match = _SSH_REGEX.match(url)
    if not http_match and not ssh_match:
        raise RuntimeError('Could not parse the URL (`%s`) '
                           'for your repository.' % url)
    if http_match:
        return '/'.join(http_match.groups())
    else:
        return '/'.join(ssh_match.groups())
911680
def redirect_url=(redirect_url)

      if !redirect_url.nil? && redirect_url.to_s.length > 800
        fail ArgumentError, "invalid value for 'redirect_url', the character length must be smaller than or equal to 800."
      end

      @redirect_url = redirect_url
    end
163330
def convert_remote_url(url)
      if url.is_a? String
        return {:url =>  URI.parse(url)}
      elsif url.is_a? Hash
        hash = { :url =>  URI.parse((url[:url] || url['url'])) }
        username = url[:username] || url['username']
        hash[:username] = username if username
        
        password = (url[:password] || url['password'])
        hash[:password] = password if password
        
        return hash
      elsif url.is_a? URI
        return { :url => url }
      else
        raise ArgumentError, "Unsupported :url, must be String, Hash, or URI: #{url.inspect}"
      end
    end
921350
def check_repository_url
      url = Gitnesse::Config.instance.repository_url
      if url.nil? || url.empty?
        add_error "You must specify a repository_url to run Gitnesse"
      else
        true
      end
    end
1192028
def url=(new_val)
      return nil if new_val == @url
      # handy - from http://stackoverflow.com/questions/1805761/check-if-url-is-valid-ruby#1805788
      url_ok = new_val =~ /\A#{URI.regexp(%w(http https))}\z/
      raise JSS::InvalidDataError, 'New value is not a valid http(s) url' unless url_ok && url_ok.zero?
      @url = new_val
      @need_to_update = true
    end
418281
def get(url)

      data = nil
      resp = HTTParty.get(url)

      if resp.code == 200
        return resp.body
      end
    end