1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 07:47:14 +03:00

Sanitise ship loadout file names

Fixes #303
This commit is contained in:
Jonathan Harris 2018-03-18 11:48:04 +00:00
parent a442b216c1
commit b102b8c5b8
4 changed files with 16 additions and 4 deletions

View File

@ -373,3 +373,15 @@ def ship(data):
# subset of "ship" that's not noisy
return filter_ship(data['ship'])
# Ship name suitable for writing to a file
def ship_file_name(ship_name, ship_type):
name = unicode(ship_name or ship_map.get(ship_type.lower(), ship_type)).strip()
if name.endswith('.'):
name = name[:-1]
if name.lower() in ['con', 'prn', 'aux', 'nul',
'com1', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'com9',
'lpt1', 'lpt2', 'lpt3', 'lpt4', 'lpt5', 'lpt6', 'lpt7', 'lpt8', 'lpt9']:
name = name + '_'
return name.translate({ ord(x): u'_' for x in ['\0', '<', '>', ':', '"', '/', '\\', '|', '?', '*'] })

View File

@ -148,7 +148,7 @@ def export(data, filename=None):
return
# Look for last ship of this type
ship = companion.ship_map.get(data['ship']['name'].lower(), data['ship']['name']) # Use in-game name
ship = companion.ship_file_name(data['ship'].get('shipName'), data['ship']['name'])
regexp = re.compile(re.escape(ship) + '\.\d\d\d\d\-\d\d\-\d\dT\d\d\.\d\d\.\d\d\.txt')
oldfiles = sorted([x for x in os.listdir(config.get('outdir')) if regexp.match(x)])
if oldfiles:

View File

@ -19,7 +19,7 @@ def export(data, filename=None):
return
# Look for last ship of this type
ship = companion.ship_map.get(data['ship']['name'].lower(), data['ship']['name']) # Use in-game name
ship = companion.ship_file_name(data['ship'].get('shipName'), data['ship']['name'])
regexp = re.compile(re.escape(ship) + '\.\d\d\d\d\-\d\d\-\d\dT\d\d\.\d\d\.\d\d\.txt')
oldfiles = sorted([x for x in os.listdir(config.get('outdir')) if regexp.match(x)])
if oldfiles:

View File

@ -13,7 +13,7 @@ if __debug__:
from traceback import print_exc
from config import config
from companion import ship_map
from companion import ship_file_name
if platform=='darwin':
@ -735,7 +735,7 @@ class EDLogs(FileSystemEventHandler):
h.write(string)
return
ship = self.state['ShipName'] or ship_map.get(self.state['ShipType'], self.state['ShipType'])
ship = ship_file_name(self.state['ShipName'], self.state['ShipType'])
regexp = re.compile(re.escape(ship) + '\.\d\d\d\d\-\d\d\-\d\dT\d\d\.\d\d\.\d\d\.txt')
oldfiles = sorted([x for x in listdir(config.get('outdir')) if regexp.match(x)])
if oldfiles: