use sanitize_filename func before writing a file to HD. Fixes #1722
This commit is contained in:
parent
ee6ce3c324
commit
fb758eaf89
|
@ -24,7 +24,6 @@ import sha
|
|||
import socket
|
||||
|
||||
from calendar import timegm
|
||||
from encodings.punycode import punycode_encode
|
||||
|
||||
import socks5
|
||||
import common.xmpp
|
||||
|
@ -750,8 +749,7 @@ class ConnectionVcard:
|
|||
|
||||
def save_vcard_to_hd(self, full_jid, card):
|
||||
jid, nick = gajim.get_room_and_nick_from_fjid(full_jid)
|
||||
nick = nick.replace('/', '_')
|
||||
puny_jid = punycode_encode(jid)
|
||||
puny_jid = helpers.sanitize_filename(jid)
|
||||
path = os.path.join(gajim.VCARD_PATH, puny_jid)
|
||||
if jid in self.room_jids:
|
||||
# remove room_jid file if needed
|
||||
|
@ -760,7 +758,7 @@ class ConnectionVcard:
|
|||
# create folder if needed
|
||||
if not os.path.isdir(path):
|
||||
os.mkdir(path, 0700)
|
||||
puny_nick = punycode_encode(nick)
|
||||
puny_nick = helpers.sanitize_filename(nick)
|
||||
path_to_file = os.path.join(gajim.VCARD_PATH, puny_jid, puny_nick)
|
||||
else:
|
||||
path_to_file = path
|
||||
|
@ -773,10 +771,9 @@ class ConnectionVcard:
|
|||
return {} if vcard was too old
|
||||
return None if we don't have cached vcard'''
|
||||
jid, nick = gajim.get_room_and_nick_from_fjid(fjid)
|
||||
nick = nick.replace('/', '_')
|
||||
puny_jid = punycode_encode(jid)
|
||||
puny_jid = helpers.sanitize_filename(jid)
|
||||
if is_fake_jid:
|
||||
puny_nick = punycode_encode(nick)
|
||||
puny_nick = helpers.sanitize_filename(nick)
|
||||
path_to_file = os.path.join(gajim.VCARD_PATH, puny_jid, puny_nick)
|
||||
else:
|
||||
path_to_file = os.path.join(gajim.VCARD_PATH, puny_jid)
|
||||
|
@ -944,11 +941,11 @@ class ConnectionVcard:
|
|||
# Save it to file
|
||||
self.save_vcard_to_hd(who, card)
|
||||
# Save the decoded avatar to a separate file too, and generate files for dbus notifications
|
||||
puny_jid = punycode_encode(frm)
|
||||
puny_jid = helpers.sanitize_filename(frm)
|
||||
puny_nick = None
|
||||
begin_path = os.path.join(gajim.AVATAR_PATH, puny_jid)
|
||||
if frm in self.room_jids:
|
||||
puny_nick = punycode_encode(resource.replace('/', '_'))
|
||||
puny_nick = helpers.sanitize_filename(resource)
|
||||
# create folder if needed
|
||||
if not os.path.isdir(begin_path):
|
||||
os.mkdir(begin_path, 0700)
|
||||
|
|
|
@ -24,6 +24,7 @@ import sys
|
|||
import stat
|
||||
import sha
|
||||
from pysqlite2 import dbapi2 as sqlite
|
||||
from encodings.punycode import punycode_encode
|
||||
|
||||
import gajim
|
||||
import logger
|
||||
|
@ -702,12 +703,14 @@ def get_os_info():
|
|||
def sanitize_filename(filename):
|
||||
'''makes sure the filename we try to write does not contain
|
||||
unacceptable characters'''
|
||||
filename = punycode_encode(filename)
|
||||
filename = filename.replace('/', '_')
|
||||
if os.name == 'nt':
|
||||
filename = filename.replace('?', '').replace(':', '').replace('!', '')\
|
||||
.replace('"', "'")
|
||||
# 48 is the limit
|
||||
if len(filename) > 48:
|
||||
extension = filename.split('.')[-1]
|
||||
filename = filename[0:48]
|
||||
|
||||
return filename
|
||||
|
|
|
@ -95,7 +95,6 @@ import signal
|
|||
import getopt
|
||||
import time
|
||||
import threading
|
||||
from encodings.punycode import punycode_encode
|
||||
|
||||
import gtkgui_helpers
|
||||
import notify
|
||||
|
@ -994,7 +993,7 @@ class Interface:
|
|||
|
||||
def save_avatar_files(self, jid, photo_decoded, puny_nick = None):
|
||||
'''Save the decoded avatar to a separate file, and generate files for dbus notifications'''
|
||||
puny_jid = punycode_encode(jid)
|
||||
puny_jid = helpers.sanitize_filename(jid)
|
||||
path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid)
|
||||
if puny_nick:
|
||||
path_to_file = os.path.join(path_to_file, puny_nick)
|
||||
|
|
|
@ -23,7 +23,6 @@ import gobject
|
|||
import pango
|
||||
import os
|
||||
import sys
|
||||
from encodings.punycode import punycode_encode
|
||||
|
||||
import vcard
|
||||
|
||||
|
@ -435,15 +434,14 @@ def get_avatar_pixbuf_from_cache(fjid, is_fake_jid = False):
|
|||
so we have new sha) or if we don't have the vcard'''
|
||||
|
||||
jid, nick = gajim.get_room_and_nick_from_fjid(fjid)
|
||||
nick = nick.replace('/', '_')
|
||||
if gajim.config.get('hide_avatar_of_transport') and\
|
||||
gajim.jid_is_transport(jid):
|
||||
# don't show avatar for the transport itself
|
||||
return None
|
||||
|
||||
puny_jid = punycode_encode(jid)
|
||||
puny_jid = helpers.sanitize_filename(jid)
|
||||
if is_fake_jid:
|
||||
puny_nick = punycode_encode(nick)
|
||||
puny_nick = helpers.sanitize_filename(nick)
|
||||
path = os.path.join(gajim.VCARD_PATH, puny_jid, puny_nick)
|
||||
else:
|
||||
path = os.path.join(gajim.VCARD_PATH, puny_jid)
|
||||
|
@ -488,7 +486,7 @@ def get_path_to_generic_or_avatar(generic, jid = None, suffix = None):
|
|||
Returns full path to the avatar image if it exists,
|
||||
otherwise returns full path to the image.'''
|
||||
if jid:
|
||||
puny_jid = punycode_encode(jid)
|
||||
puny_jid = helpers.sanitize_filename(jid)
|
||||
path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid) + suffix
|
||||
if os.path.exists(path_to_file):
|
||||
return path_to_file
|
||||
|
|
|
@ -19,7 +19,6 @@ import gobject
|
|||
import os
|
||||
import time
|
||||
import locale
|
||||
from encodings.punycode import punycode_encode
|
||||
|
||||
import gtkgui_helpers
|
||||
import message_control
|
||||
|
@ -395,8 +394,8 @@ class GCTooltip(BaseTooltip):
|
|||
properties.append((_('Status: '), show))
|
||||
|
||||
# Add avatar
|
||||
puny_name = punycode_encode(contact.name)
|
||||
puny_room = punycode_encode(contact.room_jid)
|
||||
puny_name = helpers.sanitize_filename(contact.name)
|
||||
puny_room = helpers.sanitize_filename(contact.room_jid)
|
||||
for type_ in ('jpeg', 'png'):
|
||||
file = os.path.join(gajim.AVATAR_PATH, puny_room,
|
||||
puny_name + '.' + type_)
|
||||
|
@ -475,7 +474,7 @@ class RosterTooltip(NotificationAreaTooltip):
|
|||
if not iconset:
|
||||
iconset = 'dcraven'
|
||||
file_path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
|
||||
puny_jid = punycode_encode(prim_contact.jid)
|
||||
puny_jid = helpers.sanitize_filename(prim_contact.jid)
|
||||
table_size = 3
|
||||
|
||||
for type_ in ('jpeg', 'png'):
|
||||
|
|
Loading…
Reference in New Issue