From 29ed08384f171b4faa37d0bb52b342a058db2844 Mon Sep 17 00:00:00 2001 From: Preston Hunt Date: Tue, 6 Oct 2020 08:28:49 -0700 Subject: [PATCH] unescape % in resources when accessing local filesystem - resolves github issue 7 - the local filesystem doesn't automatically translate % sequences like %20 in resource URIs - this changeset escapes the string before accessing the filesystem Signed-off-by: Preston Hunt --- htmlark.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htmlark.py b/htmlark.py index 02c2918..3c89d55 100755 --- a/htmlark.py +++ b/htmlark.py @@ -8,7 +8,7 @@ import mimetypes import sys from typing import Callable -from urllib.parse import quote +from urllib.parse import quote, unquote from urllib.parse import urljoin from urllib.parse import urlparse @@ -66,7 +66,9 @@ def _get_resource(resource_url: str) -> (str, bytes): raise NameError("HTTP URL found but requests not available") elif url_parsed.scheme == '': # '' is local file - with open(resource_url, 'rb') as f: + # unescape characters since the local filesystem won't translate them + local_path = unquote(resource_url) + with open(local_path, 'rb') as f: data = f.read() mimetype, _ = mimetypes.guess_type(resource_url) elif url_parsed.scheme == 'data':