util_url_valid_p (public)

 util_url_valid_p [ -relative ] query_url

Defined in packages/acs-tcl/tcl/utilities-procs.tcl

Check if an absolute Web URL (HTTP, HTTPS or FTP) is valid. If the 'relative' flag is set, also relative URLs are accepted. Refined regexp from https://mathiasbynens.be/demo/url-regex

Switches:
-relative (optional, boolean)
Boolean. If true, Accept also relative URLs.
Parameters:
query_url (required)
The URL to check.
Returns:
1 if the web URL is valid, 0 otherwise.
Authors:
Philip Greenspun <philg@mit.edu>
Héctor Romojaro

Partial Call Graph (max 5 caller/called nodes):
%3 test_acs_tcl__util_url_valid_p acs_tcl__util_url_valid_p (test acs-tcl) util_url_valid_p util_url_valid_p test_acs_tcl__util_url_valid_p->util_url_valid_p apidoc::format_see apidoc::format_see (public) apidoc::format_see->util_url_valid_p auth::validate_account_info auth::validate_account_info (private) auth::validate_account_info->util_url_valid_p template::data::validate::url template::data::validate::url (public) template::data::validate::url->util_url_valid_p

Testcases:
acs_tcl__util_url_valid_p
Source code:
    #
    # Does the URL look absolute?
    #
    if {$relative_p && ![regexp -nocase {^(.*://|mailto:)(.)*$} [string trim $query_url]]} {
        #
        # Relative URLs (https://datatracker.ietf.org/doc/html/rfc1808)
        #
        # Less restrictive (e.g. ../, ./, /, #g, ;x... and even an empty string
        # are valid relative URLs, see RFC above).
        #
        # At least, we check for spaces...
        #
        return [regexp -nocase {^[^\s]*$} [string trim $query_url]]
    } else {
        #
        # Absolute URLs (HTTP, HTTPS or FTP)
        #
        # The authority part of the URL should not start with either space,
        # /, $, ., ? or #, and should not have spaces until the end of line.
        #
        return [regexp -nocase {^(https?|ftp)://[^\s/$.?#][^\s]+$} [string trim $query_url]]
    }
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-tcl/tcl/utilities-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: