mirror of
https://github.com/ankitects/anki.git
synced 2025-11-11 15:17: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)
|
txt = re.sub(reg, "", txt)
|
||||||
return 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):
|
def repl(match):
|
||||||
tag = match.group(0)
|
tag = match.group(0)
|
||||||
fname = match.group("fname")
|
fname = match.group("fname")
|
||||||
if re.match("(https?|ftp)://", fname):
|
if re.match("(https?|ftp)://", fname):
|
||||||
return tag
|
return tag
|
||||||
return tag.replace(
|
return tag.replace(
|
||||||
fname, urllib.quote(fname.encode("utf-8")))
|
fname, fn(fname.encode("utf-8")))
|
||||||
for reg in self.imgRegexps:
|
for reg in self.imgRegexps:
|
||||||
string = re.sub(reg, repl, string)
|
string = re.sub(reg, repl, string)
|
||||||
return string
|
return string
|
||||||
|
|
|
||||||
|
|
@ -450,8 +450,7 @@ class Editor(object):
|
||||||
# misbehaving apps may include a null byte in the text
|
# misbehaving apps may include a null byte in the text
|
||||||
txt = txt.replace("\x00", "")
|
txt = txt.replace("\x00", "")
|
||||||
# reverse the url quoting we added to get images to display
|
# reverse the url quoting we added to get images to display
|
||||||
txt = unicode(urllib2.unquote(
|
txt = self.mw.col.media.escapeImages(txt, unescape=True)
|
||||||
txt.encode("utf8")), "utf8", "replace")
|
|
||||||
self.note.fields[self.currentField] = txt
|
self.note.fields[self.currentField] = txt
|
||||||
if not self.addMode:
|
if not self.addMode:
|
||||||
self.note.flush()
|
self.note.flush()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue