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#18267: eww: should trim contents, which affects history Date: Thu, 14 Aug 2014 21:15:20 +0000 Message-ID: <87wqaapyc7.fsf@violet.siamics.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1408050984 28692 80.91.229.3 (14 Aug 2014 21:16:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 14 Aug 2014 21:16:24 +0000 (UTC) To: 18267@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 14 23:16:18 2014 Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org> 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 <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>) id 1XI2Ne-0003F9-D1 for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Aug 2014 23:16:18 +0200 Original-Received: from localhost ([::1]:56490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>) id 1XI2Nd-0006Gz-Uo for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Aug 2014 17:16:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1XI2NV-0006Fy-Cw for bug-gnu-emacs@gnu.org; Thu, 14 Aug 2014 17:16:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1XI2NO-00034c-Of for bug-gnu-emacs@gnu.org; Thu, 14 Aug 2014 17:16:09 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:36717) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1XI2NO-00034U-BJ for bug-gnu-emacs@gnu.org; Thu, 14 Aug 2014 17:16:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1XI2NN-0007vb-R0 for bug-gnu-emacs@gnu.org; Thu, 14 Aug 2014 17:16:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ivan Shmakov <ivan@siamics.net> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org> Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 14 Aug 2014 21:16:01 +0000 Resent-Message-ID: <handler.18267.B.140805093530427@debbugs.gnu.org> Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 18267 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: submit@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.140805093530427 (code B ref -1); Thu, 14 Aug 2014 21:16:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 14 Aug 2014 21:15:35 +0000 Original-Received: from localhost ([127.0.0.1]:43659 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>) id 1XI2Mw-0007ug-9y for submit@debbugs.gnu.org; Thu, 14 Aug 2014 17:15:34 -0400 Original-Received: from fely.am-1.org ([78.47.74.50]:50522) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from <ivan@siamics.net>) id 1XI2Ms-0007uS-B5 for submit@debbugs.gnu.org; Thu, 14 Aug 2014 17:15:31 -0400 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:Date:Sender:Subject:To:From; bh=jcyDUvn+jKH1LezoaSwLmu7sFfTTbuew/3N4lmrS6DI=; b=Wm16TDzuNktgVl3tznq0q8Tk6WAtmR2tPurZlDWnUbcVFTIB9hweV+5hL6bwTS419uX1lYkwuiMP0fDWwUmwzl5Y4yXgrHALFlge3bonUUQKL/wzPvJ285hXEwzb5nry5ne/WpRQy4vnVbRSHCotXcayUNXP5OCb1Hri8/drk6w=; 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 <ivan@siamics.net>) id 1XI2Mq-0004Xn-Ge for submit@debbugs.gnu.org; Thu, 14 Aug 2014 21:15:29 +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 <ivan@siamics.net>) id 1XI2Mj-0002bZ-CB for submit@debbugs.gnu.org; Fri, 15 Aug 2014 04:15:21 +0700 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" <bug-gnu-emacs.gnu.org> List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>, <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe> List-Archive: <http://lists.gnu.org/archive/html/bug-gnu-emacs> List-Post: <mailto:bug-gnu-emacs@gnu.org> List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help> List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>, <mailto:bug-gnu-emacs-request@gnu.org?subject=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:92474 Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/92474> --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Package: emacs Severity: minor Tags: patch EWW currently fails to trim any leading and trailing whitespace /and/ newline codes off the <title /> contents, as in the following (valid) HTML document: <!DOCTYPE html> <title> A title with newlines. Here, eww-current-title will be "\nA title with newlines.\n", which causes the *eww-history* buffer contents to be formatted like: A title with newlines. http://example.org/ Which, in turn, causes eww-history-browse to fail (unless used on the first line of such an entry), due to the use of (line-beginning-position): (let ((history (get-text-property (line-beginning-position) 'eww-history)= )) (unless history (error "No history on the current line")) (quit-window) I suggest that this issue be resolved as follows: =E2=80=A2 eww-tag-title is changed to strip any [[:blank:]\r\n]+ from the element textual content; (it may also turn any embedded [\r\n] codes into ordinary blanks, though it isn=E2=80=99t /strictly/ necessary given the rest of the changes below); =E2=80=A2 eww-list-histories turns any control characters in :title into something printable (say, using the caret notation; ^J for \n, etc.; this doesn=E2=80=99t cover non-ASCII controls, though); =E2=80=A2 the eww-history property is made to cover the whole *eww-history* entry, =E2=80=93 not just its initial character; conversely, eww-history-browse is changed to use (point) instead of (line-beginning-position). Also, while we=E2=80=99re at it, I suggest getting rid of the right-padding of the /last/ (as in: second) field of the history records, for it=E2=80=99s entirely unnecessary, and makes copying the URIs from *eww-history* harder. A possible patch is MIMEd. (Note that the eww-tag-title change looks a bit too verbose, though.) --=20 FSF associate member #7257 http://boycottsystemd.org/ =E2=80=A6 3013 B6A0= 230E 334A --=-=-= Content-Type: text/x-diff Content-Disposition: inline --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -344,10 +387,20 @@ word(s) will be searched for via `eww-search-prefix'." (setq header-line-format nil))) (defun eww-tag-title (cont) - (setq eww-current-title "") - (dolist (sub cont) - (when (eq (car sub) 'text) - (setq eww-current-title (concat eww-current-title (cdr sub))))) + (setq eww-current-title + (with-temp-buffer + (dolist (sub cont) + (when (eq (car sub) 'text) + (insert (cdr sub)))) + ;; trim leading and trailing whitespace + (goto-char (point-min)) + (when (re-search-forward "^[[:blank:]\r\n]+" nil t) + (replace-match "")) + (goto-char (point-max)) + (when (re-search-backward "[[:blank:]\r\n]+$" nil t) + (replace-match "")) + ;; . + (buffer-string))) (eww-update-header-line-format)) (defun eww-tag-body (cont) @@ -1303,23 +1370,29 @@ Differences in #targets are ignored." (setq start (point)) (setq domain-length (max domain-length (length (plist-get history :url)))) (setq title-length (max title-length (length (plist-get history :title))))) - (setq format (format "%%-%ds %%-%ds" title-length domain-length) + (setq format (format "%%-%ds %%s" title-length) header-line-format (concat " " (format format "Title" "URL"))) (dolist (history eww-history-trans) (setq start (point)) (setq url (plist-get history :url)) - (setq title (plist-get history :title)) + (with-temp-buffer + (insert (plist-get history :title)) + (goto-char (point-min)) + (while (re-search-forward "[\000-\037]" nil t) + (replace-match + (string ?^ (logior ?@ (aref (match-string 0) 0))))) + (setq title (buffer-string))) (insert (format format title url)) (insert "\n") - (put-text-property start (1+ start) 'eww-history history)) + (put-text-property start (point) 'eww-history history)) (goto-char (point-min))) (pop-to-buffer "*eww history*"))) (defun eww-history-browse () "Browse the history under point in eww." (interactive) - (let ((history (get-text-property (line-beginning-position) 'eww-history))) + (let ((history (get-text-property (point) 'eww-history))) (unless history (error "No history on the current line")) (quit-window) --=-=-=--