From 93717df30bf0a4ddd227af2fc49c8f2e5b1b9b80 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 17 May 2013 11:34:15 +0900 Subject: [PATCH] fix pasting/attaching with unicode chars (#813, #867) - treat # specially instead of quoting entire string, as urllib unfortunately can't handle utf8 quoted text - make sure we pass utf8 to quote() in _addMedia() --- aqt/editor.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index 0de63c921..cce6e554b 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -817,7 +817,7 @@ to a cloze type first, via Edit>Change Note Type.""")) # return a local html link ext = name.split(".")[-1].lower() if ext in pics: - return '' % urllib.quote(name) + return '' % urllib.quote(name.encode("utf8")) else: anki.sound.play(name) return '[sound:%s]' % name @@ -1097,8 +1097,8 @@ class EditorWebView(AnkiWebView): ext = url.split(".")[-1].lower() if ext not in pics and ext not in audio: return - if url.lower().startswith("file:/"): - url = urllib.quote(url, safe="/:") + if url.lower().startswith("file://"): + url = url.replace("#", "%23") # fetch it into a temporary folder self.editor.mw.progress.start( immediate=True, parent=self.editor.parentWindow) @@ -1112,6 +1112,7 @@ class EditorWebView(AnkiWebView): finally: self.editor.mw.progress.finish() path = unicode(urllib2.unquote(url.encode("utf8")), "utf8") + path = path.replace("#", "") path = namedtmp(os.path.basename(path)) file = open(path, "wb") file.write(filecontents)