Skip to content

Commit

Permalink
wam: Allow using embedded data URIs as add-on icons
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
irydacea committed May 8, 2018
1 parent c92b9de commit 4335bed
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -148,6 +148,7 @@
* Fixed the wesnoth(6) manpage claiming the default log level is 'error' when it
has been 'warning' since version 1.9.0.
* Avoid trying to load invalid base64-encoded data URIs.
* wesnoth_addon_manager and the addons.wesnoth.org web index can now use data URIs.

## Version 1.13.12
### Security fixes
Expand Down
61 changes: 35 additions & 26 deletions data/tools/addon_manager/html.py
Expand Up @@ -4,6 +4,7 @@
import html
import glob
import os
import re
import sys
import time
import urllib.parse
Expand Down Expand Up @@ -260,32 +261,40 @@ def w(line):

if icon:
icon = icon.strip()
tilde = icon.find("~")
if tilde >= 0:
icon = icon[:tilde]
if "\\" in icon:
icon = icon.replace("\\", "/")
try:
os.mkdir(path + "/icons")
except OSError:
pass
if "." not in icon:
icon += ".png"
src = root_dir + icon
imgurl = "icons/" + os.path.basename(icon)
if not os.path.exists(src):
src = root_dir + "data/core/images/" + icon
if not os.path.exists(src):
src = root_dir + "images/" + icon
if not os.path.exists(src):
src = glob.glob(root_dir + "data/campaigns/*/images/" + icon)
if src:
src = src[0]
if not src or not os.path.exists(src):
sys.stderr.write("Cannot find icon " + icon + "\n")
src = root_dir + "images/misc/missing-image.png"
imgurl = "icons/missing-image.png"
images_to_tc.append((src, path + "/" + imgurl))
uri_manifest = re.match('^data:(image/(?:png|jpeg));base64,', icon)

if uri_manifest:
if uri_manifest.group(1) not in ('image/png', 'image/jpeg'):
sys.stderr.write("Data URI icon using unsupported content type " + uri_manifest.group(1))
else:
imgurl = icon
else:
tilde = icon.find("~")
if tilde >= 0:
icon = icon[:tilde]
if "\\" in icon:
icon = icon.replace("\\", "/")
try:
os.mkdir(path + "/icons")
except OSError:
pass
if "." not in icon:
icon += ".png"
src = root_dir + icon
imgurl = "icons/" + os.path.basename(icon)
if not os.path.exists(src):
src = root_dir + "data/core/images/" + icon
if not os.path.exists(src):
src = root_dir + "images/" + icon
if not os.path.exists(src):
src = glob.glob(root_dir + "data/campaigns/*/images/" + icon)
if src:
src = src[0]
if not src or not os.path.exists(src):
sys.stderr.write("Cannot find icon " + icon + "\n")
src = root_dir + "images/misc/missing-image.png"
imgurl = "icons/missing-image.png"
images_to_tc.append((src, path + "/" + imgurl))

w('<tr>')

Expand Down

0 comments on commit 4335bed

Please sign in to comment.