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