unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#45355: 26.1; shr-tag-base doesn't handle <base href=""> properly
@ 2020-12-21 20:35 Łukasz Stelmach
  2020-12-22  6:47 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Łukasz Stelmach @ 2020-12-21 20:35 UTC (permalink / raw)
  To: 45355

[-- Attachment #1: Type: text/plain, Size: 538 bytes --]


For what it's worth, W3C HTML Validator claims that a document with an
empty string in the href attribute of a base tag

    <base href="">

is valid. I found such document recently in my INBOX and Gnus was unable
to display it correctly because the second string-match in
shr-parse-base breaks when local is nil. My solution is not to call
shr-parse-base not only when href is not present but also when href is
an empty string.

The patch has been crated on the current master branch.
-- 
Kind regards,
Łukasz Stelmach

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Handle-gracefully-href-in-base-tags.patch --]
[-- Type: text/x-diff, Size: 932 bytes --]

From f92e8b8ab5b6f0970611c91cf80e418712ed2b58 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Stelmach?= <stlman@poczta.fm>
Date: Mon, 21 Dec 2020 21:07:28 +0100
Subject: [PATCH] Handle gracefully href="" in base tags

* net/shr.el (shr-tag-base): shr-parse-base can't handle empty strings
gracefully. Don't call it unless href is a non-empty string.
---
 lisp/net/shr.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 2e5dd5ffa5..150ad88d4c 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -1516,8 +1516,9 @@ ones, in case fg and bg are nil."
       plist)))
 
 (defun shr-tag-base (dom)
-  (when-let* ((base (dom-attr dom 'href)))
-    (setq shr-base (shr-parse-base base)))
+  (let* ((base (dom-attr dom 'href)))
+    (when (> (length base) 0)
+      (setq shr-base (shr-parse-base base))))
   (shr-generic dom))
 
 (defun shr-tag-a (dom)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#45355: 26.1; shr-tag-base doesn't handle <base href=""> properly
  2020-12-21 20:35 bug#45355: 26.1; shr-tag-base doesn't handle <base href=""> properly Łukasz Stelmach
@ 2020-12-22  6:47 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-22  6:47 UTC (permalink / raw)
  To: Łukasz Stelmach; +Cc: 45355

Łukasz Stelmach <steelman@post.pl> writes:

> For what it's worth, W3C HTML Validator claims that a document with an
> empty string in the href attribute of a base tag
>
>     <base href="">
>
> is valid. I found such document recently in my INBOX and Gnus was unable
> to display it correctly because the second string-match in
> shr-parse-base breaks when local is nil. My solution is not to call
> shr-parse-base not only when href is not present but also when href is
> an empty string.
>
> The patch has been crated on the current master branch.

Looks good to me; I've now applied it to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-22  6:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-21 20:35 bug#45355: 26.1; shr-tag-base doesn't handle <base href=""> properly Łukasz Stelmach
2020-12-22  6:47 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).