Hello,

Attached is a patch to fix https://savannah.gnu.org/bugs/?55087. This patch is slightly hacky (<source srcset> in a media element is allowed), but the code as-is also allows for <source src> in a <picture> and <source> outside of a <picture> or media element.
From 1d51ad4f18b325c659073a55fc3fffa5bdd3f72f Mon Sep 17 00:00:00 2001
From: blankie <blan...@nixnetmail.com>
Date: Mon, 1 Jan 2024 23:27:49 +1100
Subject: [PATCH] * src/html-url.c: Parse <source srcset> attributes

Bug-Id: 55087
---
 src/html-url.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/html-url.c b/src/html-url.c
index 896d6fc4..275a7740 100644
--- a/src/html-url.c
+++ b/src/html-url.c
@@ -55,7 +55,7 @@ typedef void (*tag_handler_t) (int, struct taginfo *, struct map_context *);
 DECLARE_TAG_HANDLER (tag_find_urls);
 DECLARE_TAG_HANDLER (tag_handle_base);
 DECLARE_TAG_HANDLER (tag_handle_form);
-DECLARE_TAG_HANDLER (tag_handle_img);
+DECLARE_TAG_HANDLER (tag_handle_img_and_source);
 DECLARE_TAG_HANDLER (tag_handle_link);
 DECLARE_TAG_HANDLER (tag_handle_meta);
 
@@ -105,7 +105,7 @@ static struct known_tag {
   { TAG_FORM,    "form",        tag_handle_form },
   { TAG_FRAME,   "frame",       tag_find_urls },
   { TAG_IFRAME,  "iframe",      tag_find_urls },
-  { TAG_IMG,     "img",         tag_handle_img },
+  { TAG_IMG,     "img",         tag_handle_img_and_source },
   { TAG_INPUT,   "input",       tag_find_urls },
   { TAG_LAYER,   "layer",       tag_find_urls },
   { TAG_LINK,    "link",        tag_handle_link },
@@ -118,7 +118,7 @@ static struct known_tag {
   { TAG_TH,      "th",          tag_find_urls },
   { TAG_VIDEO,   "video",       tag_find_urls },
   { TAG_AUDIO,   "audio",       tag_find_urls },
-  { TAG_SOURCE,  "source",      tag_find_urls }
+  { TAG_SOURCE,  "source",      tag_handle_img_and_source }
 };
 
 /* tag_url_attributes documents which attributes of which tags contain
@@ -184,7 +184,7 @@ static const char *additional_attributes[] = {
   "content",                    /* used by tag_handle_meta  */
   "action",                     /* used by tag_handle_form  */
   "style",                      /* used by check_style_attr */
-  "srcset",                     /* used by tag_handle_img */
+  "srcset",                     /* used by tag_handle_img_and_source */
 };
 
 static struct hash_table *interesting_tags;
@@ -679,12 +679,15 @@ tag_handle_meta (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *
     }
 }
 
-/* Handle the IMG tag.  This requires special handling for the srcset attr,
-   while the traditional src/lowsrc/href attributes can be handled generically.
+/* Handle the IMG and SOURCE tags.  These require special handling for the
+   srcset attr, while the traditional src/lowsrc/href attributes can be
+   handled generically.
 */
 
 static void
-tag_handle_img (int tagid, struct taginfo *tag, struct map_context *ctx) {
+tag_handle_img_and_source (int tagid, struct taginfo *tag,
+                           struct map_context *ctx)
+{
   int attrind;
   char *srcset;
 
-- 
2.43.0

Reply via email to