filename must be a full path
This commit is contained in:
parent
0bb066a8b8
commit
e2d5a1c8aa
|
@ -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/')
|
await cfg.option('a').value.set('/tmp/')
|
||||||
await cfg.option('a').value.set('/tmp/text.txt')
|
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')
|
|
||||||
with pytest.raises(ValueError):
|
|
||||||
await cfg.option('a').value.set('/tmp/with space.txt')
|
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('/tmp/with$.txt')
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
await cfg.option('a').value.set('not starts with /')
|
||||||
assert not await list_sessions()
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,17 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from ..i18n import _
|
from ..i18n import _
|
||||||
from .stroption import RegexpOption
|
from .stroption import StrOption
|
||||||
|
|
||||||
|
|
||||||
class FilenameOption(RegexpOption):
|
class FilenameOption(StrOption):
|
||||||
__slots__ = tuple()
|
__slots__ = tuple()
|
||||||
_regexp = re.compile(r"^[a-zA-Z0-9\-\._~/+]+$")
|
|
||||||
_type = 'filename'
|
_type = 'filename'
|
||||||
_display_name = _('file name')
|
_display_name = _('file name')
|
||||||
|
|
||||||
|
def validate(self,
|
||||||
|
value: str,
|
||||||
|
) -> None:
|
||||||
|
super().validate(value)
|
||||||
|
if not value.startswith('/'):
|
||||||
|
raise ValueError(_('must starts with "/"'))
|
||||||
|
|
Loading…
Reference in New Issue