From: Ivan Shmakov <ivan@siamics.net>
To: 18267@debbugs.gnu.org
Subject: bug#18267: eww: should trim <title /> contents, which affects history
Date: Thu, 14 Aug 2014 21:15:20 +0000 [thread overview]
Message-ID: <87wqaapyc7.fsf@violet.siamics.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 1939 bytes --]
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.
</title>
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:
• eww-tag-title is changed to strip any [[:blank:]\r\n]+ from
the <title /> element textual content; (it may also turn any
embedded [\r\n] codes into ordinary blanks, though it isn’t
/strictly/ necessary given the rest of the changes below);
• eww-list-histories turns any control characters in :title into
something printable (say, using the caret notation; ^J for \n,
etc.; this doesn’t cover non-ASCII controls, though);
• the eww-history property is made to cover the whole
*eww-history* entry, – not just its initial character;
conversely, eww-history-browse is changed to use (point)
instead of (line-beginning-position).
Also, while we’re at it, I suggest getting rid of the
right-padding of the /last/ (as in: second) field of the history
records, for it’s 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.)
--
FSF associate member #7257 http://boycottsystemd.org/ … 3013 B6A0 230E 334A
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff, Size: 2245 bytes --]
--- 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)
next reply other threads:[~2014-08-14 21:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-14 21:15 Ivan Shmakov [this message]
2014-11-10 21:25 ` bug#18267: eww: should trim <title /> contents, which affects history Lars Magne Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wqaapyc7.fsf@violet.siamics.net \
--to=ivan@siamics.net \
--cc=18267@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.