Skip to content

Commit

Permalink
Expand _string_is_url() protocol-specific patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
xwmx committed Feb 8, 2022
1 parent 2848b6f commit 322100b
Show file tree
Hide file tree
Showing 2 changed files with 1,412 additions and 5 deletions.
39 changes: 38 additions & 1 deletion nb
Original file line number Diff line number Diff line change
Expand Up @@ -3005,7 +3005,44 @@ _string_is_email() {
# 0 (success, true) If the string is a recognized URL.
# 1 (error, false) if not.
_string_is_url() {
[[ "${1:-}" =~ ^https\:\/\/|^http\:\/\/|^file\:\/\/|^ftp\:\/\/|^sftp\:\/\/ ]]
[[ -z "${1:-}" ]] && return 1

# # https://en.wikipedia.org/wiki/List_of_URI_schemes
local _url_patterns=(
-e "(afp|attachment|platform):/"
-e "(aaas?|acap|adiumxtra|aw|beshare|bolo|chrome|chrome-extension)://"
-e "(coaps?|content|crid|cvs|dict|dns|ed2k|facetime|feed|file|finger|fish)://"
-e "(ftp|git|gizmoproject|go|gopher|h323|http|https|imap|irc|irc6|ircs)://"
-e "(keyparc|lastfm|ldaps?|market|message|mms|ms-help|mumble|ni|nntp)://"
-e "(notes|payto|pop|res|resource|rmi|rsync|rtmfp|rtmp|s3|secondlife)://"
-e "(sftp|sgn|smb|snmp|soldat|ssh|steam|svn|svn+ssh|teamspeak|telnet)://"
-e "(udp|unreal|ut2004|ventrilo|vnc|wais|webcal|wtai|wyciwyg|xri)://"
-e "(z39.50r|z39.50s|admin|app|stratum\+tcp|stratum\+udp|web-[a-z]+)://"
-e "(zoommtg|zoomus|slack)://"
-e "(aim):[^[:space:]]+\?[^[:space:]]+"
-e "(dab|fm):[^[:space:]]+\.[^[:space:]]+\.[^[:space:]]+"
-e "(data|geo):[^[:space:]]+,[^[:space:]]+"
-e "(msnim|things):[^[:space:]]+\?[^[:space:]]+"
-e "(feed|mvn|paparazzi|view-source):https?://"
-e "gtalk:chat"
-e "(im|mailto|reload|sips?|xmpp):[^[:space:]]+\@[^[:space:]]+"
-e "jar:[^[:space:]]+\!\/"
-e "magnet:\?xt=urn:"
-e "maps:q="
-e "(sms|tel):\+[0-9]+"
-e "(jdbc|spotify|urn):[^[:space:]]+:[^[:space:]]+"
-e "tag:[^[:space:]]+,[^[:space:]]+:[^[:space:]]+"
-e "ymsgr:sendIM?"
-e "doi:10\."
# TODO: develop strategy to avoid matching selectors
# -e "(apt|amss|barion|bitcoin|callto|cid|dns|drm|fax|gg|go):[^[:space:]]+"
# -e "(iax|javascript|message|mid|mvn|news|openpgp4fpr|palm):[^[:space:]]+"
# -e "(pres|proxy|psyc|query|session|shc|skype|stuns?):[^[:space:]]+"
# -e "(trueconf|turns?|ws|xfire):[^[:space:]]+"
# -e "itms:"
)

printf "%s\\n" "${1:-}" | grep -E -q --color=never "${_url_patterns[@]:-}"
}

# _wrap()
Expand Down
Loading

0 comments on commit 322100b

Please sign in to comment.