URI validation for URI schemes which allows only scheme, host and path components.
349271
private function isUriWithSchemeHostAndPathOnly()
    {
        return null === $this->user_info
            && null === $this->port
            && null === $this->query
            && null === $this->fragment
            && !('' != $this->scheme && null === $this->host);
    }
502559
def is_safe_url(url, host=None):
    
    if url is not None:
        url = url.strip()
    if not url:
        return False
    # Chrome treats \ completely as /
    url = url.replace("\\", "/")
    # Chrome considers any URL with more than two slashes to be absolute, but
    # urlparse is not so flexible. Treat any url with three slashes as unsafe.
    if url.startswith("///"):
        return False
    url_info = urlparse(url)
    # Forbid URLs like http:///example.com - with a scheme, but without a
    # hostname.
    # In that URL, example.com is not the hostname but, a path component.
    # However, Chrome will still consider example.com to be the hostname,
    # so we must not allow this syntax.
    if not url_info.netloc and url_info.scheme:
        return False
    # Forbid URLs that start with control characters. Some browsers (like
    # Chrome) ignore quite a few control characters at the start of a
    # URL and might consider the URL as scheme relative.
    if unicodedata.category(url[0])[0] == "C":
        return False
    return (not url_info.netloc or url_info.netloc == host) and (
        not url_info.scheme or url_info.scheme in {"http", "https"}
    )
197507
public static boolean isAbsoluteURI(String systemId)
  {
     /** http://www.ietf.org/rfc/rfc2396.txt
      *   Authors should be aware that a path segment which contains a colon
      * character cannot be used as the first segment of a relative URI path
      * (e.g., "this:that"), because it would be mistaken for a scheme name.
     **/
     /** 
      * %REVIEW% Can we assume here that systemId is a valid URI?
      * It looks like we cannot ( See discussion of this common problem in 
      * Bugzilla Bug 22777 ). 
     **/
     //"fix" for Bugzilla Bug 22777
    if(isWindowsAbsolutePath(systemId)){
        return false;
     }
    
    final int fragmentIndex = systemId.indexOf('#');
    final int queryIndex = systemId.indexOf('?');
    final int slashIndex = systemId.indexOf('/');
    final int colonIndex = systemId.indexOf(':');
    
    //finding substring  before '#', '?', and '/' 
    int index = systemId.length() -1;
    if(fragmentIndex > 0) 
        index = fragmentIndex;
    if((queryIndex > 0) && (queryIndex <index)) 
        index = queryIndex;
    if((slashIndex > 0) && (slashIndex <index))
        index = slashIndex; 
    // return true if there is ':' before '#', '?', and '/'
    return ((colonIndex >0) && (colonIndex<index));
    
  }
93770
def absolute_uri(self, location=None, scheme=None, **query):
        
        if not is_absolute_uri(location):
            if location or location is None:
                location = self.full_path(location, **query)
            if not scheme:
                scheme = self.is_secure and 'https' or 'http'
            base = '%s://%s' % (scheme, self.get_host())
            return '%s%s' % (base, location)
        elif not scheme:
            return iri_to_uri(location)
        else:
            raise ValueError('Absolute location with scheme not valid')
121723
private void verify() {
		if (!this.encoded) {
			return;
		}
		verifyUriComponent(getScheme(), Type.SCHEME);
		verifyUriComponent(this.userInfo, Type.USER_INFO);
		verifyUriComponent(this.host, getHostType());
		this.path.verify();
		for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
			verifyUriComponent(entry.getKey(), Type.QUERY_PARAM);
			for (String value : entry.getValue()) {
				verifyUriComponent(value, Type.QUERY_PARAM);
			}
		}
		verifyUriComponent(getFragment(), Type.FRAGMENT);
	}
256276
def is_uri_to_be_filtered(uri, filter_list):
    """"""
    match = False
    if filter_list:
        for uri_filter in filter_list:
            if re.search(uri_filter, uri, flags=re.IGNORECASE):
                match = True
        return match
948046
def in_general_ns(uri):
    """"""
    RDFuri = RDF.uri
    RDFSuri = RDFS.uri

    for ns in (RDFuri, RDFSuri, OWL, SKOS, DC):
        if uri.startswith(ns):
            return True
    return False
1325555
public static boolean isURLFedoraServer(String url) {

        // scheme must be http or https
        URI uri = URI.create(url);
        String scheme = uri.getScheme();
        if (!scheme.equals("http") && !scheme.equals("https")) {
            return false;
        }

        // host must be configured hostname or localhost
        String fHost = CONFIG.getParameter(FEDORA_SERVER_HOST,Parameter.class).getValue();
        String host = uri.getHost();
        if (!host.equals(fHost) && !host.equals("localhost")) {
            return false;
        }

        // path must begin with configured webapp context
        String path = uri.getPath();
        String fedoraContext = CONFIG.getParameter(
                FEDORA_SERVER_CONTEXT,Parameter.class).getValue();
        if (!path.startsWith("/" + fedoraContext + "/")) {
            return false;
        }

        // port specification must match http or https port as appropriate
        String httpPort = CONFIG.getParameter(FEDORA_SERVER_PORT,Parameter.class).getValue();
        String httpsPort = CONFIG.getParameter(FEDORA_REDIRECT_PORT,Parameter.class).getValue();
        if (uri.getPort() == -1) {
            // unspecified, so fedoraPort must be 80 (http), or 443 (https)
            if (scheme.equals("http")) {
                return httpPort.equals("80");
            } else {
                return httpsPort.equals("443");
            }
        } else {
            // specified, so must match appropriate http or https port
            String port = "" + uri.getPort();
            if (scheme.equals("http")) {
                return port.equals(httpPort);
            } else {
                return port.equals(httpsPort);
            }
        }

    }
1004614
def is_url(string, allowed_schemes=None):
    
    if not is_full_string(string):
        return False
    valid = bool(URL_RE.search(string))
    if allowed_schemes:
        return valid and any([string.startswith(s) for s in allowed_schemes])
    return valid
952932
public static void checkUriScheme(String scheme, String message, Object... args) {
    String uri = String.format("%s://null", scheme);
    try {
      new URI(uri);
    } catch (URISyntaxException e) {
      throw new IllegalArgumentException(String.format(message, args));
    }
  }
862573
def __parse_uri(self):
        """"""
        if self.scheme:
            scheme = '{}://'.format(self.scheme)
        else:
            scheme = ''

        credentials = self.username or ''
        password = self.password or ''

        if credentials and password:
            credentials = self.username + ':' + self.password
        if credentials:
            credentials += '@'

        if self.port:
            location = '{}:{}'.format(self.host, self.port)
        else:
            location = self.host

        path = self.path or ''

        if self.query:
            query = '?' + self.query
        else:
            query = ''

        if self.fragment:
            fragment = '#' + self.fragment
        else:
            fragment = ''

        return scheme + credentials + location + path + query + fragment
352393
function baseStringUri(uri) {
    var parsed = url.parse(uri);

    //  The port MUST be included if it is not the default port for the
    //  scheme, and MUST be excluded if it is the default.
    if (parsed.protocol === 'https:/') {
        parsed.host = parsed.host.replace(/:443$/, '');
    } else if (parsed.protocol === 'http:/') {
        parsed.host = parsed.host.replace(/:80$/, '');
    }

    return url.format({
        protocol: parsed.protocol,
        host: parsed.host,
        auth: parsed.auth,
        pathname: parsed.pathname
    });
}
231486
def _parse_free_uri_scheme(self):
        """"""
        valid = "abcdefghijklmnopqrstuvwxyz0123456789+.-"
        scheme = []
        try:
            # We have to backtrack through the textbuffer looking for our
            # scheme since it was just parsed as text:
            for chunk in reversed(self._textbuffer):
                for char in reversed(chunk):
                    if char.isspace() or char in self.MARKERS:
                        raise StopIteration()
                    if char not in valid:
                        raise BadRoute()
                    scheme.append(char)
        except StopIteration:
            pass
        scheme = "".join(reversed(scheme))
        slashes = self._read() == self._read(1) == "/"
        if not is_scheme(scheme, slashes):
            raise BadRoute()
        self._push(self._context | contexts.EXT_LINK_URI)
        self._emit_text(scheme)
        self._emit_text(":")
        if slashes:
            self._emit_text("//")
            self._head += 2
183080
public static String stripURLScheme(String url) {
		String lcUrl = url.toLowerCase();
		for(String scheme : ALL_SCHEMES) {
			if(lcUrl.startsWith(scheme)) {
				return url.substring(scheme.length());
			}
		}
		return url;
	}
518304
def validate_registry_uri_authority(auth: str) -> None:
    
    if is_ens_domain(auth) is False and not is_checksum_address(auth):
        raise ValidationError(f"{auth} is not a valid registry URI authority.")
1027471
protected boolean isForbidden(URI uri)
    {
        String scheme = uri.getScheme();
        String host = uri.getHost();
        int port = uri.getPort();
        return isForbidden(scheme, host, port, true);
    }
545888
public static function validate_domain(String $scheme, String $host)
    {
        // Dynamic URL
        $url = $scheme . '://' . $host;

        // Validate URL
        if (self::validate_url($url)) {
            // Validate HTTP request scheme
            self::validate_scheme(parse_url($url)['scheme']);
        } else {
            throw new Exception('Invalid URL: "' . $url . '"');
        }
    }