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):
- 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