mirror of
https://github.com/ankitects/anki.git
synced 2025-11-11 23:27:12 -05:00
limit url unquoting to image tags
this prevents random text like %20 in a field from being converted when note is saved
This commit is contained in:
parent
f8bf8afe4a
commit
d53346d783
2 changed files with 7 additions and 4 deletions
|
|
@ -221,14 +221,18 @@ create table meta (dirMod int, lastUsn int); insert into meta values (0, 0);
|
|||
txt = re.sub(reg, "", txt)
|
||||
return txt
|
||||
|
||||
def escapeImages(self, string):
|
||||
def escapeImages(self, string, unescape=False):
|
||||
if unescape:
|
||||
fn = urllib.unquote
|
||||
else:
|
||||
fn = urllib.quote
|
||||
def repl(match):
|
||||
tag = match.group(0)
|
||||
fname = match.group("fname")
|
||||
if re.match("(https?|ftp)://", fname):
|
||||
return tag
|
||||
return tag.replace(
|
||||
fname, urllib.quote(fname.encode("utf-8")))
|
||||
fname, fn(fname.encode("utf-8")))
|
||||
for reg in self.imgRegexps:
|
||||
string = re.sub(reg, repl, string)
|
||||
return string
|
||||
|
|
|
|||
|
|
@ -450,8 +450,7 @@ class Editor(object):
|
|||
# misbehaving apps may include a null byte in the text
|
||||
txt = txt.replace("\x00", "")
|
||||
# reverse the url quoting we added to get images to display
|
||||
txt = unicode(urllib2.unquote(
|
||||
txt.encode("utf8")), "utf8", "replace")
|
||||
txt = self.mw.col.media.escapeImages(txt, unescape=True)
|
||||
self.note.fields[self.currentField] = txt
|
||||
if not self.addMode:
|
||||
self.note.flush()
|
||||
|
|
|
|||
Loading…
Reference in a new issue