Ad blocker leaves stray JSON in cache dir when server does not send application/json MIME type
To reproduce this, configure a content filter HTTP URL that returns anything else than application/json
as MIME type. For example GitHub sends Content-Type: text/html
when fetching raw blob contents, so the following will trigger this bug:
gsettings set org.gnome.Epiphany content-filters \
"['https://github.com/erictsangx/youtube-content-blocker/raw/master/X-YouTube/blockerList.json']"
Then there will be a stale .json
file under ~/.cache/epiphany/adblock
, and Epiphany logs a warning like the following:
jun 04 16:51:18 momiji epiphany[205089]: Filter source file:///home/aperez/.cache/epiphany/adblock/86d78309e74afc2815620d401060196a12f253b873b8e1d8a809472a67ae81dc-205089.json has invalid MIME type: text/plain
I think there are two (possibly complementary) things to do here:
- If the MIME type sent by the server is
text/plain
,application/x-octet-stream
, or any other which is kind of a catch-all and that a misconfigured HTTP server may be sending for JSON content, useg_file_query_info()
+g_file_info_get_content_type()
and proceed with loading if it turns out the downloaaded data is JSON after all. - If checks fail, and the file won't be loaded after all, remove it instead of leaving it on disk.