Function: textsec-link-suspicious-p

textsec-link-suspicious-p is a byte-compiled function defined in textsec.el.gz.

Signature

(textsec-link-suspicious-p LINK)

Documentation

Say whether LINK is suspicious.

LINK should be a cons cell where the first element is the URL, and the second element is the link text.

This function will return non-nil if it seems like the link text is misleading about where the URL takes you. This is typical when the link text looks like an URL itself, but doesn't lead to the same domain as the URL.

Source Code

;; Defined in /usr/src/emacs/lisp/international/textsec.el.gz
(defun textsec-link-suspicious-p (link)
  "Say whether LINK is suspicious.
LINK should be a cons cell where the first element is the URL,
and the second element is the link text.

This function will return non-nil if it seems like the link text
is misleading about where the URL takes you.  This is typical
when the link text looks like an URL itself, but doesn't lead to
the same domain as the URL."
  (let* ((url (car link))
         (text (string-trim (cdr link))))
    (catch 'found
      (let ((udomain (url-host (url-generic-parse-url url)))
            (tdomain (url-host (url-generic-parse-url text))))
        (cond
         ((and udomain
               tdomain
               (not (equal udomain tdomain))
               ;; One may be a sub-domain of the other, but don't allow too
               ;; short domains.
               (not (or (and (string-suffix-p udomain tdomain)
                             (url-domsuf-cookie-allowed-p udomain))
                        (and (string-suffix-p tdomain udomain)
                             (url-domsuf-cookie-allowed-p tdomain)))))
          (throw 'found
                 (format "Text `%s' doesn't point to link URL `%s'"
                         text url)))
         ((and tdomain
               (textsec-domain-suspicious-p tdomain))
          (throw 'found
                 (format "Domain `%s' in the link text is suspicious"
                         (bidi-string-strip-control-characters
                          tdomain)))))))))