Skip to content

Commit

Permalink
Merge pull request #3446 from atlas-engineer/minor-scheme-review
Browse files Browse the repository at this point in the history
  • Loading branch information
aadcg committed Aug 5, 2024
2 parents b37501a + 293016c commit c3b6bd7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
4 changes: 2 additions & 2 deletions source/renderer/gtk.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,8 @@ See `finalize-buffer'."
(log:debug "Load URL in new buffer: ~a" (render-url (url request-data)))
(nyxt::open-urls (list (url request-data)))
(webkit:webkit-policy-decision-ignore response-policy-decision))
((not (valid-scheme-p (quri:uri-scheme (url request-data))))
(uiop:launch-program (list *open-program* (quri:render-uri (url request-data)))))
((null (valid-scheme-p (quri:uri-scheme (url request-data))))
(log:warn "Unsupported URI scheme: ~s." (quri:uri-scheme (url request-data))))
((not (known-type-p request-data))
(log:debug "Initiate download of ~s." (render-url (url request-data)))
(webkit:webkit-policy-decision-download response-policy-decision))
Expand Down
42 changes: 19 additions & 23 deletions source/urls.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -141,42 +141,38 @@ signatures."
(defun valid-tld-p (hostname)
"Return NIL if HOSTNAME does not include a valid TLD as determined by the
Public Suffix list, T otherwise."
(sera:true (cl:ignore-errors (cl-tld:get-tld hostname))))
(ignore-errors (cl-tld:get-tld hostname)))

(export-always 'browser-schemes)
(defgeneric browser-schemes (browser)
(:method-combination append)
(:documentation "Return a list of schemes supported by a browser"))
(:documentation "Return a list of schemes supported by BROWSER."))

;; Set specifier to T because *BROWSER* can be bound to NIL
(defmethod browser-schemes append ((browser t))
(let ((nyxt-schemes (append '("blob" "javascript") (alex:hash-table-keys *schemes*)))
;; List of URI schemes: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
;; Last updated 2020-08-26.
;; Last updated 2024-08-05.
(iana-schemes
'("aaa" "aaas" "about" "acap" "acct" "cap" "cid" "coap" "coap+tcp" "coap+ws"
"coaps" "coaps+tcp" "coaps+ws" "crid" "data" "dav" "dict" "dns" "example" "file"
"ftp" "geo" "go" "gopher" "h323" "http" "https" "iax" "icap" "im" "imap" "info"
"ipp" "ipps" "iris" "iris.beep" "iris.lwz" "iris.xpc" "iris.xpcs" "jabber"
"ldap" "leaptofrogans" "mailto" "mid" "msrp" "msrps" "mtqp" "mupdate" "news"
"nfs" "ni" "nih" "nntp" "opaquelocktoken" "pkcs11" "pop" "pres" "reload" "rtsp"
"rtsps" "rtspu" "service" "session" "shttp" "sieve" "sip" "sips" "sms" "snmp"
"soap.beep" "soap.beeps" "stun" "stuns" "tag" "tel" "telnet" "tftp"
"thismessage" "tip" "tn3270" "turn" "turns" "tv" "urn" "vemmi" "vnc" "ws" "wss"
"xcon" "xcon-userid" "xmlrpc.beep" "xmlrpc.beeps" "xmpp" "z39.50r" "z39.50s"))
;; https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.xml
;; TODO: Remove when https://github.com/lu4nx/cl-tld/issues/2 is fixed.
(special-use-schemes
'("example" "invalid" "local" "localhost" "onion" "test")))
(append nyxt-schemes iana-schemes special-use-schemes)))
'("aaa" "aaas" "about" "acap" "acct" "cap" "cid" "coap" "coap+tcp"
"coap+ws" "coaps" "coaps+tcp" "coaps+ws" "crid" "data" "dav" "dict"
"dns" "dtn" "example" "file" "ftp" "geo" "go" "gopher" "h323" "http"
"https" "iax" "icap" "im" "imap" "info" "ipn" "ipp" "ipps" "iris"
"iris.beep" "iris.lwz" "iris.xpc" "iris.xpcs" "jabber" "ldap"
"leaptofrogans" "mailto" "mid" "msrp" "msrps" "mt" "mtqp" "mupdate"
"mvrp" "mvrps" "news" "nfs" "ni" "nih" "nntp" "opaquelocktoken"
"pkcs11" "pop" "pres" "reload" "rtsp" "rtsps" "rtspu" "service"
"session" "shttp" "sieve" "sip" "sips" "sms" "snmp" "soap.beep"
"soap.beeps" "stun" "stuns" "tag" "tel" "telnet" "tftp"
"thismessage" "tip" "tn3270" "turn" "turns" "tv" "urn" "vemmi" "vnc"
"ws" "wss" "xcon" "xcon-userid" "xmlrpc.beep" "xmlrpc.beeps" "xmpp"
"z39.50r" "z39.50s")))
(append nyxt-schemes iana-schemes)))

(export-always 'valid-scheme-p)
(defun valid-scheme-p (scheme)
"Whether the scheme is supported by Nyxt.
Usually means that either:
- SCHEME is IANA-approved,
- or SCHEME is a Nyxt-specific `scheme'."
(sera:true (find scheme (browser-schemes *browser*) :test #'string=)))
"Whether SCHEME is supported."
(find scheme (browser-schemes *browser*) :test #'string=))

(export-always 'valid-url-p)
(defun valid-url-p (url &key (check-tld-p t))
Expand Down

0 comments on commit c3b6bd7

Please sign in to comment.