From 10c5057a8ac5094f8dac88c97cb79f7154b10a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Sat, 7 Aug 2021 20:34:13 +0200 Subject: [PATCH] Fix the rel attribute handling for link tags --- libwget/html_url.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/libwget/html_url.c b/libwget/html_url.c index 076de722..f3399778 100644 --- a/libwget/html_url.c +++ b/libwget/html_url.c @@ -222,18 +222,36 @@ static void html_get_url(void *context, int flags, const char *tag, const char * if ((*tag|0x20) == 'l' && !wget_strcasecmp_ascii(tag, "link")) { if (!wget_strcasecmp_ascii(attr, "rel")) { - if (!wget_strncasecmp_ascii(val, "shortcut icon", len) - || !wget_strncasecmp_ascii(val, "stylesheet", len) - || !wget_strncasecmp_ascii(val, "preload", len)) - ctx->link_inline = 1; - else - ctx->link_inline = 0; + ctx->link_inline = 0; + + // "rel" contains a space separated list of items. + // see https://html.spec.whatwg.org/multipage/semantics.html#attr-link-rel + // see https://html.spec.whatwg.org/multipage/links.html#linkTypes + while (len) { + const char *p; + + for (p = val;len && !c_isspace(*val); val++, len--); // find end of item + if (p == val) { val++; len--; continue; } // found a delimiter + + // Check for items that may be important to display the page. + if (!wget_strncasecmp_ascii(p, "icon", val - p) + || !wget_strncasecmp_ascii(p, "manifest", val - p) + || !wget_strncasecmp_ascii(p, "modulepreload", val - p) + || !wget_strncasecmp_ascii(p, "stylesheet", val - p) + || !wget_strncasecmp_ascii(p, "prefetch", val - p) + || !wget_strncasecmp_ascii(p, "preload", val - p)) + { + ctx->link_inline = 1; + break; + } + } if (ctx->uri_index >= 0) { // href= came before rel= wget_html_parsed_url *url = wget_vector_get(res->uris, ctx->uri_index); url->link_inline = ctx->link_inline; } + return; } }