From b4333ca2fddc18e6553a8ee7613e5fcb0d9747bd Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 10 May 2017 04:24:56 +0100 Subject: [PATCH] Added code to prevent crashing when URLs contain non-ASCII characters. Does not guarantee handling of non-UTF-8 URLs (like ISO 8859-15, Shift-JIS, etc) --- wrp.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/wrp.py b/wrp.py index 2d7486c..af356a9 100755 --- a/wrp.py +++ b/wrp.py @@ -262,11 +262,11 @@ if sys.platform == "linux" or sys.platform == "linux2": turl = QUrl(web_url).resolved(QUrl(x.attribute('href'))).toString() xmin, ymin, xmax, ymax = x.geometry().getCoords() if ISMAP == "true": - mapfile.write("rect %s %i,%i %i,%i\n" % (turl, xmin, ymin, xmax, ymax)) + mapfile.write("rect %s %i,%i %i,%i\n".decode('utf-8', errors='ignore') % (turl, xmin, ymin, xmax, ymax)) else: httpout.write("\"%s\"\n" + " ALT=\"%s\" HREF=\"%s\">\n".decode('utf-8', errors='ignore') % (xmin, ymin, xmax, ymax, turl, turl)) if ISMAP != "true": @@ -547,6 +547,7 @@ elif sys.platform == "darwin": % ttl.toPlainText()).encode('utf-8', errors='ignore')) break # Don't repeat bad HTML coding with several title marks httpout.write("\n\n") + if ISMAP == "true": httpout.write("" "\"wrp-render\"\n" @@ -571,11 +572,11 @@ elif sys.platform == "darwin": ymax = Foundation.NSMaxY(myrect) if ISMAP == "true": - mapfile.write("rect %s %i,%i %i,%i\n" % (turl, xmin, ymin, xmax, ymax)) + mapfile.write("rect %s %i,%i %i,%i\n".decode('utf-8', errors='ignore') % (turl, xmin, ymin, xmax, ymax)) else: httpout.write("\"%s\"\n" + " ALT=\"%s\" HREF=\"%s\">\n".decode('utf-8', errors='ignore') % (xmin, ymin, xmax, ymax, turl, turl)) i += 1