Skip to content

Commit

Permalink
Merge pull request #1372 from Stomern/parse-icon-by-content-type
Browse files Browse the repository at this point in the history
Fix feed icon not parsing if the URL doesn't have a file extension
  • Loading branch information
lwindolf committed Sep 25, 2024
2 parents 9ca2ad6 + 7f71f04 commit ed7cc7a
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/subscription_icon.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,23 @@ subscription_icon_download_html_cb (const struct updateResult * const result, gp
}

static GRegex *image_extension_match = NULL;
static GRegex *image_mime_type_match = NULL;

static void
subscription_icon_handle_response (const struct updateResult * const result, gpointer user_data, updateFlags flags)
{
if (!image_extension_match)
image_extension_match = g_regex_new ("\\.(ico|png|gif|jpg|svg)$", G_REGEX_CASELESS, 0, NULL);

if (!image_mime_type_match)
image_mime_type_match = g_regex_new ("^image/(png|gif|jpeg|svg+xml)$", G_REGEX_CASELESS, 0, NULL);

if ((result->contentType && g_regex_match (image_mime_type_match, result->contentType, 0, NULL)) || g_regex_match (image_extension_match, result->data, 0, NULL)) {
subscription_icon_download_data_cb(result, user_data, flags);
} else {
subscription_icon_download_html_cb(result, user_data, flags);
}
}

/* Performs a download of the first URL in ctxt->urls */
static void
Expand Down Expand Up @@ -156,15 +173,7 @@ subscription_icon_download_next (iconDownloadCtxtPtr ctxt)
ctxt->options
);

if (!image_extension_match)
image_extension_match = g_regex_new ("\\.(ico|png|gif|jpg|svg)$", G_REGEX_CASELESS, 0, NULL);

if (g_regex_match (image_extension_match, url, 0, NULL))
callback = subscription_icon_download_data_cb;
else
callback = subscription_icon_download_html_cb;

update_execute_request (node_from_id (ctxt->id), request, callback, ctxt, FEED_REQ_PRIORITY_HIGH | FEED_REQ_NO_FEED);
update_execute_request (node_from_id (ctxt->id), request, subscription_icon_handle_response, ctxt, FEED_REQ_PRIORITY_HIGH | FEED_REQ_NO_FEED);
} else {
debug (DEBUG_UPDATE, "Icon '%s' discovery/download failed!", ctxt->id);
subscription_icon_download_ctxt_free (ctxt);
Expand Down

0 comments on commit ed7cc7a

Please sign in to comment.