mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
block illegal filename characters
This commit is contained in:
parent
95106908dd
commit
d94f6d2011
1 changed files with 14 additions and 4 deletions
|
@ -5,7 +5,7 @@
|
||||||
import os, shutil, re, urllib, urllib2, time, unicodedata, \
|
import os, shutil, re, urllib, urllib2, time, unicodedata, \
|
||||||
urllib, sys, simplejson, zipfile
|
urllib, sys, simplejson, zipfile
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
from anki.utils import checksum, intTime, namedtmp, isWin
|
from anki.utils import checksum, intTime, namedtmp, isWin, isMac
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from anki.db import DB
|
from anki.db import DB
|
||||||
from anki.consts import *
|
from anki.consts import *
|
||||||
|
@ -230,9 +230,9 @@ If the same name exists, compare checksums."""
|
||||||
data = z.read(i)
|
data = z.read(i)
|
||||||
csum = checksum(data)
|
csum = checksum(data)
|
||||||
name = meta[i.filename]
|
name = meta[i.filename]
|
||||||
# malicious chars?
|
# can we store the file on this system?
|
||||||
for c in '/\\':
|
if self.illegal(i.filename):
|
||||||
assert c not in name
|
continue
|
||||||
# save file
|
# save file
|
||||||
open(name, "wb").write(data)
|
open(name, "wb").write(data)
|
||||||
# update db
|
# update db
|
||||||
|
@ -250,6 +250,16 @@ If the same name exists, compare checksums."""
|
||||||
self.syncMod()
|
self.syncMod()
|
||||||
return finished
|
return finished
|
||||||
|
|
||||||
|
def illegal(self, f):
|
||||||
|
if isWin:
|
||||||
|
for c in f:
|
||||||
|
if c in "<>:\"/\\|?*^":
|
||||||
|
return True
|
||||||
|
elif isMac:
|
||||||
|
for c in f:
|
||||||
|
if c in ":\\/":
|
||||||
|
return True
|
||||||
|
|
||||||
# Media syncing - bundling zip files to send to server
|
# Media syncing - bundling zip files to send to server
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# Because there's no standard filename encoding for zips, and because not
|
# Because there's no standard filename encoding for zips, and because not
|
||||||
|
|
Loading…
Reference in a new issue