If an avatar or vcard filename is > 48, use its hash for filename instead. I used the md5
method already in the same file. Fixes #4273.
This commit is contained in:
parent
8b945f69fa
commit
e76817e77e
1 changed files with 7 additions and 6 deletions
|
@ -841,18 +841,19 @@ def get_os_info():
|
||||||
return 'N/A'
|
return 'N/A'
|
||||||
|
|
||||||
def sanitize_filename(filename):
|
def sanitize_filename(filename):
|
||||||
'''makes sure the filename we will write does contain only
|
'''makes sure the filename we will write does contain only acceptable and
|
||||||
acceptable and latin characters'''
|
latin characters, and is not too long (in that case hash it)'''
|
||||||
|
# 48 is the limit
|
||||||
|
if len(filename) > 48:
|
||||||
|
hash = hash_md5(filename)
|
||||||
|
filename = base64.b64encode(hash.digest())
|
||||||
|
|
||||||
filename = punycode_encode(filename) # make it latin chars only
|
filename = punycode_encode(filename) # make it latin chars only
|
||||||
filename = filename.replace('/', '_')
|
filename = filename.replace('/', '_')
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
filename = filename.replace('?', '_').replace(':', '_')\
|
filename = filename.replace('?', '_').replace(':', '_')\
|
||||||
.replace('\\', '_').replace('"', "'").replace('|', '_')\
|
.replace('\\', '_').replace('"', "'").replace('|', '_')\
|
||||||
.replace('*', '_').replace('<', '_').replace('>', '_')
|
.replace('*', '_').replace('<', '_').replace('>', '_')
|
||||||
# 48 is the limit
|
|
||||||
if len(filename) > 48:
|
|
||||||
extension = filename.split('.')[-1]
|
|
||||||
filename = filename[0:48]
|
|
||||||
|
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue