Properly escape pasted URLs

If a URL is pasted and it isn't converted to a media link, then it
should be treated as normal text and properly escaped.
This commit is contained in:
Gabriel McManus 2018-09-23 11:39:04 +00:00
parent 5ae73d96d7
commit 893ebfab60

View file

@ -582,7 +582,7 @@ to a cloze type first, via Edit>Change Note Type."""))
def urlToLink(self, url): def urlToLink(self, url):
fname = self.urlToFile(url) fname = self.urlToFile(url)
if not fname: if not fname:
return url return None
return self.fnameToLink(fname) return self.fnameToLink(fname)
def fnameToLink(self, fname): def fnameToLink(self, fname):
@ -915,8 +915,10 @@ class EditorWebView(AnkiWebView):
# if the user is pasting an image or sound link, convert it to local # if the user is pasting an image or sound link, convert it to local
if self.editor.isURL(txt): if self.editor.isURL(txt):
txt = txt.split("\r\n")[0] url = txt.split("\r\n")[0]
return self.editor.urlToLink(txt) link = self.editor.urlToLink(url)
if link:
return link
# normal text; convert it to HTML # normal text; convert it to HTML
txt = html.escape(txt) txt = html.escape(txt)