structly validation

This commit is contained in:
Maxim Devaev 2023-03-06 04:18:38 +02:00
parent 5495f70564
commit 7667834b6d
5 changed files with 21 additions and 31 deletions

View File

@ -138,7 +138,7 @@ class Storage:
def __filter(self, items: list[str]) -> Generator[str, None, None]: def __filter(self, items: list[str]) -> Generator[str, None, None]:
for item in sorted(map(str.strip, items)): for item in sorted(map(str.strip, items)):
if not item.startswith(".__") and item != "lost+found": if not item.startswith(".") and item != "lost+found":
yield item yield item
def get_image_by_name(self, name: str) -> Image: def get_image_by_name(self, name: str) -> Image:

View File

@ -48,8 +48,6 @@ def valid_msd_image_name(arg: Any) -> str:
raise_error(arg, name) raise_error(arg, name)
for (index, part) in enumerate(list(parts)): for (index, part) in enumerate(list(parts)):
parts[index] = valid_printable_filename(part, name=name) parts[index] = valid_printable_filename(part, name=name)
if part.startswith(".__") or part == "lost+found":
raise_error(part, name)
return "/".join(parts) return "/".join(parts)

View File

@ -78,7 +78,12 @@ def valid_printable_filename(arg: Any, name: str="") -> str:
arg = valid_stripped_string_not_empty(arg, name) arg = valid_stripped_string_not_empty(arg, name)
if "/" in arg or "\0" in arg or arg in [".", ".."]: if (
"/" in arg
or "\0" in arg
or arg.startswith(".")
or arg == "lost+found"
):
raise_error(arg, name) raise_error(arg, name)
arg = "".join( arg = "".join(

View File

@ -72,14 +72,6 @@ def test_fail__valid_atx_button(arg: Any) -> None:
("\n" + "x" * 1000, "x" * 255), ("\n" + "x" * 1000, "x" * 255),
("test", "test"), ("test", "test"),
("test test [test] #test$", "test test [test] #test$"), ("test test [test] #test$", "test test [test] #test$"),
(".test", ".test"),
("..test", "..test"),
("..тест..", "..тест.."),
("..те\\ст..", "..те\\ст.."),
(".....", "....."),
(".....txt", ".....txt"),
(" .. .", ".. ."),
("..\n.", ".._."),
("test/", "test"), ("test/", "test"),
("/test", "test"), ("/test", "test"),
("foo/bar.iso", "foo/bar.iso"), ("foo/bar.iso", "foo/bar.iso"),
@ -104,12 +96,13 @@ def test_ok__valid_msd_image_name(arg: Any, retval: str) -> None:
"/ ..", "/ ..",
".. /", ".. /",
"/.. /", "/.. /",
".test",
"foo/../bar.iso", "foo/../bar.iso",
"foo/./foo.iso", "foo/./foo.iso",
"foo/lost+found/bar.iso", "foo/lost+found/bar.iso",
"../bar.iso", "../bar.iso",
"/../bar.iso", "/../bar.iso",
"foo/.__bar.iso", "foo/.bar.iso",
"", "",
" ", " ",
None, None,

View File

@ -90,14 +90,6 @@ def test_fail__valid_abs_path__dir(arg: Any) -> None:
("\n" + "x" * 1000, "x" * 255), ("\n" + "x" * 1000, "x" * 255),
("test", "test"), ("test", "test"),
("test test [test] #test$", "test test [test] #test$"), ("test test [test] #test$", "test test [test] #test$"),
(".test", ".test"),
("..test", "..test"),
("..тест..", "..тест.."),
("..те\\ст..", "..те\\ст.."),
(".....", "....."),
(".....txt", ".....txt"),
(" .. .", ".. ."),
("..\n.", ".._."),
]) ])
def test_ok__valid_printable_filename(arg: Any, retval: str) -> None: def test_ok__valid_printable_filename(arg: Any, retval: str) -> None:
assert valid_printable_filename(arg) == retval assert valid_printable_filename(arg) == retval
@ -110,6 +102,7 @@ def test_ok__valid_printable_filename(arg: Any, retval: str) -> None:
"test/", "test/",
"/test", "/test",
"../test", "../test",
".test",
"./.", "./.",
"../.", "../.",
"./..", "./..",
@ -117,6 +110,7 @@ def test_ok__valid_printable_filename(arg: Any, retval: str) -> None:
"/ ..", "/ ..",
".. /", ".. /",
"/.. /", "/.. /",
"lost+found",
"", "",
" ", " ",
None, None,