From 5d6c5ef2b40bffab271d0a377664fc2ff7e9c353 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 17 Feb 2018 15:47:26 -0800 Subject: [PATCH] Raise exception if attempted override name is invalid. Technically it doesn't really matter because the override is not used for any file ops, but I don't like the idea of busted path-looking strings being displayed anywhere on the interface. --- etiquette/objects.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index 077852d..d7f930b 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -1036,10 +1036,12 @@ class Photo(ObjectBase): self.__reinit__() def set_override_filename(self, new_filename, *, commit=True): - if not new_filename: - new_filename = None - else: - new_filename = helpers.remove_path_badchars(new_filename) + if new_filename is not None: + cleaned = helpers.remove_path_badchars(new_filename) + cleaned = cleaned.strip() + if not cleaned: + raise ValueError('"%s" is not valid.' % new_filename) + new_filename = cleaned data = { 'id': self.id, @@ -1051,6 +1053,8 @@ class Photo(ObjectBase): self.photodb.log.debug('Committing - set override filename') self.photodb.commit() + self.__reinit__() + def sorted_tags(self): tags = self.get_tags() tags.sort(key=lambda x: x.qualified_name())