From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Shmakov Newsgroups: gmane.emacs.bugs Subject: bug#19556: eww: make URI rewriting fully customizable Date: Sat, 10 Jan 2015 18:05:20 +0000 Message-ID: <87y4pazf33.fsf@violet.siamics.net> References: <87sifi22rg.fsf@violet.siamics.net> <831tn27m78.fsf@gnu.org> <87lhla1yx2.fsf@violet.siamics.net> <83vbke62wi.fsf@gnu.org> <8761ce1rit.fsf@violet.siamics.net> <83r3v25ygd.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1420913186 6388 80.91.229.3 (10 Jan 2015 18:06:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 10 Jan 2015 18:06:26 +0000 (UTC) To: 19556@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jan 10 19:06:17 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YA0QO-00076U-2C for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Jan 2015 19:06:12 +0100 Original-Received: from localhost ([::1]:55856 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YA0QN-0006jp-1n for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Jan 2015 13:06:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YA0QI-0006jX-H0 for bug-gnu-emacs@gnu.org; Sat, 10 Jan 2015 13:06:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YA0QF-0004AV-9M for bug-gnu-emacs@gnu.org; Sat, 10 Jan 2015 13:06:06 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:60960) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YA0QE-0004AR-RX for bug-gnu-emacs@gnu.org; Sat, 10 Jan 2015 13:06:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YA0QE-00052l-IE for bug-gnu-emacs@gnu.org; Sat, 10 Jan 2015 13:06:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ivan Shmakov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Jan 2015 18:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19556 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 19556-submit@debbugs.gnu.org id=B19556.142091313219317 (code B ref 19556); Sat, 10 Jan 2015 18:06:02 +0000 Original-Received: (at 19556) by debbugs.gnu.org; 10 Jan 2015 18:05:32 +0000 Original-Received: from localhost ([127.0.0.1]:42093 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YA0Pj-00051S-P1 for submit@debbugs.gnu.org; Sat, 10 Jan 2015 13:05:32 -0500 Original-Received: from fely.am-1.org ([78.47.74.50]:48791) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YA0Ph-00051I-2T for 19556@debbugs.gnu.org; Sat, 10 Jan 2015 13:05:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=siamics.net; s=a2013295; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:Sender:References:Subject:To:From; bh=0VFKEa8L1ukxxMOfSGoJtV1F1Lh7DtopFLDJTaEyafE=; b=pUg87brR1XzK91P/45Afit5oAVvWD4SDfsUW+SPvwrYtnGMKLNjBKlKU9QWbdCYzBCGNLkmSoyWZVpUdF46YZ/JnTsX+uvawM350m8zm2ZcuLq+50fFR1BlSw8mztyAf6WI6bZkGZxijBGvQG8i+GzzzJppnJ1o2rDxexPid0os=; Original-Received: from [2a02:2560:6d4:26ca::1:1d] (helo=violet.siamics.net) by fely.am-1.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1YA0Pf-0003K6-PT for 19556@debbugs.gnu.org; Sat, 10 Jan 2015 18:05:28 +0000 Original-Received: from localhost ([::1] helo=violet.siamics.net) by violet.siamics.net with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1YA0PY-0003Dh-LP for 19556@debbugs.gnu.org; Sun, 11 Jan 2015 01:05:20 +0700 Mail-Followup-To: 19556@debbugs.gnu.org In-Reply-To: <83r3v25ygd.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 10 Jan 2015 19:37:22 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:98190 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >>>>> Eli Zaretskii writes: [=E2=80=A6] > Similarly, eww's job is to find and visit a URL, which includes > processing file:// URLs, and that functionality should always be in > the function, not in any hook. file: URIs=E2=80=99 processing is the responsibility of url-file.el. There=E2=80=99s nothing in =E2=80=98eww=E2=80=99 which ever deals with suc= h URIs, =E2=80=93 /except/ for a simple guard which tells: =E2=80=9Cif it begins with =E2=80=98file:/=E2=80=99, do /not/ never, ever mangle it.=E2=80=9D Personally, I=E2=80=99d rather appreciate having such a guard for https: and http: URIs at the least, =E2=80=93 if only for the sake of consistency. [=E2=80=A6] > To _override_ behavior, we provide function variables that get used > _instead_ of the default. Like indent-region-function, for example. > So in that case, you'd need to make 'eww' call the value of > eww-mangle-uri-function, whose default value is a function that does > what the current code does inside eww itself, and then users could > override that by providing their own URI-mangling function. Please consider the patch MIMEd. * lisp/net/eww.el (eww-uri-rewrite-function): New customizable variable. (eww): Use eww-uri-rewrite-function. (eww-mangle-uri): New function, split off eww. --=20 FSF associate member #7257 http://boycottsystemd.org/ =E2=80=A6 3013 B6A0= 230E 334A --=-=-= Content-Type: text/diff Content-Disposition: inline --- a/lisp/net/eww.el 2015-01-10 16:26:37 +0000 +++ b/lisp/net/eww.el 2015-01-10 17:59:44 +0000 @@ -75,6 +75,15 @@ url-get-url-at-point eww-current-url)) +(defcustom eww-uri-rewrite-function + 'eww-uri-rewrite + "A function to call to pre-process the argument to `eww'." + :version "25.1" + :group 'eww + :type 'hook + :options '(eww-uri-rewrite + identity)) + (defcustom eww-bookmarks-directory user-emacs-directory "Directory where bookmark files will be stored." :version "25.1" @@ -249,28 +258,7 @@ (if uris (format " (default %s)" (car uris)) "") ": "))) (list (read-string prompt nil nil uris)))) - (setq url (string-trim url)) - (cond ((string-match-p "\\`file:/" url)) - ;; Don't mangle file: URLs at all. - ((string-match-p "\\`ftp://" url) - (user-error "FTP is not supported.")) - (t - (if (or (string-match "\\`https?:" url) - ;; Also try to match "naked" URLs like - ;; en.wikipedia.org/wiki/Free software - (string-match "\\`[A-Za-z_]+\\.[A-Za-z._]+/" url) - (and (= (length (split-string url)) 1) - (or (and (not (string-match-p "\\`[\"\'].*[\"\']\\'" url)) - (> (length (split-string url "[.:]")) 1)) - (string-match eww-local-regex url)))) - (progn - (unless (string-match-p "\\`[a-zA-Z][-a-zA-Z0-9+.]*://" url) - (setq url (concat "http://" url))) - ;; Some sites do not redirect final / - (when (string= (url-filename (url-generic-parse-url url)) "") - (setq url (concat url "/")))) - (setq url (concat eww-search-prefix - (replace-regexp-in-string " " "+" url)))))) + (setq url (funcall eww-uri-rewrite-function (string-trim url))) (if (eq major-mode 'eww-mode) (when (or (plist-get eww-data :url) (plist-get eww-data :dom)) @@ -556,6 +545,31 @@ (list (get-text-property (point) 'shr-url) (get-text-property (point) 'image-url)))) +(defun eww-uri-rewrite (url) + (cond ((string-match-p "\\`file:/" url)) + ;; Don't mangle file: URLs at all. + ((string-match-p "\\`ftp://" url) + (user-error "FTP is not supported.")) + (t + (if (or (string-match "\\`https?:" url) + ;; Also try to match "naked" URLs like + ;; en.wikipedia.org/wiki/Free software + (string-match "\\`[A-Za-z_]+\\.[A-Za-z._]+/" url) + (and (= (length (split-string url)) 1) + (or (and (not (string-match-p "\\`[\"\'].*[\"\']\\'" url)) + (> (length (split-string url "[.:]")) 1)) + (string-match eww-local-regex url)))) + (progn + (unless (string-match-p "\\`[a-zA-Z][-a-zA-Z0-9+.]*://" url) + (setq url (concat "http://" url))) + ;; Some sites do not redirect final / + (when (string= (url-filename (url-generic-parse-url url)) "") + (setq url (concat url "/")))) + (setq url (concat eww-search-prefix + (replace-regexp-in-string " " "+" url)))))) + ;; . + url) + (defun eww-view-source () "View the HTML source code of the current page." (interactive) --=-=-=--