From e2d5a1c8aaf62f51e118330b7e7062f0e6d49b3e Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 17 Feb 2021 09:50:36 +0100 Subject: [PATCH] filename must be a full path --- tests/test_config_api.py | 9 +++------ tiramisu/option/filenameoption.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/test_config_api.py b/tests/test_config_api.py index 2bfa337..27036ee 100644 --- a/tests/test_config_api.py +++ b/tests/test_config_api.py @@ -323,13 +323,10 @@ async def test_filename(config_type): await cfg.option('a').value.set('/tmp') await cfg.option('a').value.set('/tmp/') await cfg.option('a').value.set('/tmp/text.txt') - await cfg.option('a').value.set('tmp') - await cfg.option('a').value.set('tmp/') - await cfg.option('a').value.set('tmp/text.txt') + await cfg.option('a').value.set('/tmp/with space.txt') + await cfg.option('a').value.set('/tmp/with$.txt') with pytest.raises(ValueError): - await cfg.option('a').value.set('/tmp/with space.txt') - with pytest.raises(ValueError): - await cfg.option('a').value.set('/tmp/with$.txt') + await cfg.option('a').value.set('not starts with /') assert not await list_sessions() diff --git a/tiramisu/option/filenameoption.py b/tiramisu/option/filenameoption.py index ad0d2cb..7abdc0e 100644 --- a/tiramisu/option/filenameoption.py +++ b/tiramisu/option/filenameoption.py @@ -21,11 +21,17 @@ import re from ..i18n import _ -from .stroption import RegexpOption +from .stroption import StrOption -class FilenameOption(RegexpOption): +class FilenameOption(StrOption): __slots__ = tuple() - _regexp = re.compile(r"^[a-zA-Z0-9\-\._~/+]+$") _type = 'filename' _display_name = _('file name') + + def validate(self, + value: str, + ) -> None: + super().validate(value) + if not value.startswith('/'): + raise ValueError(_('must starts with "/"'))