Skip to content

Commit ed7cc7a

Browse files
authored
Merge pull request #1372 from Stomern/parse-icon-by-content-type
Fix feed icon not parsing if the URL doesn't have a file extension
2 parents 9ca2ad6 + 7f71f04 commit ed7cc7a

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/subscription_icon.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,23 @@ subscription_icon_download_html_cb (const struct updateResult * const result, gp
128128
}
129129

130130
static GRegex *image_extension_match = NULL;
131+
static GRegex *image_mime_type_match = NULL;
132+
133+
static void
134+
subscription_icon_handle_response (const struct updateResult * const result, gpointer user_data, updateFlags flags)
135+
{
136+
if (!image_extension_match)
137+
image_extension_match = g_regex_new ("\\.(ico|png|gif|jpg|svg)$", G_REGEX_CASELESS, 0, NULL);
138+
139+
if (!image_mime_type_match)
140+
image_mime_type_match = g_regex_new ("^image/(png|gif|jpeg|svg+xml)$", G_REGEX_CASELESS, 0, NULL);
141+
142+
if ((result->contentType && g_regex_match (image_mime_type_match, result->contentType, 0, NULL)) || g_regex_match (image_extension_match, result->data, 0, NULL)) {
143+
subscription_icon_download_data_cb(result, user_data, flags);
144+
} else {
145+
subscription_icon_download_html_cb(result, user_data, flags);
146+
}
147+
}
131148

132149
/* Performs a download of the first URL in ctxt->urls */
133150
static void
@@ -156,15 +173,7 @@ subscription_icon_download_next (iconDownloadCtxtPtr ctxt)
156173
ctxt->options
157174
);
158175

159-
if (!image_extension_match)
160-
image_extension_match = g_regex_new ("\\.(ico|png|gif|jpg|svg)$", G_REGEX_CASELESS, 0, NULL);
161-
162-
if (g_regex_match (image_extension_match, url, 0, NULL))
163-
callback = subscription_icon_download_data_cb;
164-
else
165-
callback = subscription_icon_download_html_cb;
166-
167-
update_execute_request (node_from_id (ctxt->id), request, callback, ctxt, FEED_REQ_PRIORITY_HIGH | FEED_REQ_NO_FEED);
176+
update_execute_request (node_from_id (ctxt->id), request, subscription_icon_handle_response, ctxt, FEED_REQ_PRIORITY_HIGH | FEED_REQ_NO_FEED);
168177
} else {
169178
debug (DEBUG_UPDATE, "Icon '%s' discovery/download failed!", ctxt->id);
170179
subscription_icon_download_ctxt_free (ctxt);

0 commit comments

Comments
 (0)