* bug#18267: eww: should trim <title /> contents, which affects history
@ 2014-08-14 21:15 Ivan Shmakov
2014-11-10 21:25 ` Lars Magne Ingebrigtsen
0 siblings, 1 reply; 2+ messages in thread
From: Ivan Shmakov @ 2014-08-14 21:15 UTC (permalink / raw)
To: 18267
[-- 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)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-11-10 21:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-14 21:15 bug#18267: eww: should trim <title /> contents, which affects history Ivan Shmakov
2014-11-10 21:25 ` Lars Magne Ingebrigtsen
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.