Skip to content

Commit b6664cf

Browse files
committed
Added additional validation to path in Route constructor
1 parent 17ea206 commit b6664cf

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

adafruit_httpserver/route.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,23 @@ def _validate_path(path: str, append_slash: bool) -> None:
5555
if not path.startswith("/"):
5656
raise ValueError("Path must start with a slash.")
5757

58+
if path.endswith("/") and append_slash:
59+
raise ValueError("Cannot use append_slash=True when path ends with /")
60+
61+
if "//" in path:
62+
raise ValueError("Path cannot contain double slashes.")
63+
5864
if "<>" in path:
5965
raise ValueError("All URL parameters must be named.")
6066

61-
if path.endswith("/") and append_slash:
62-
raise ValueError("Cannot use append_slash=True when path ends with /")
67+
if re.search(r"[^/]<[^/]+>|<[^/]+>[^/]", path):
68+
raise ValueError("All URL parameters must be between slashes.")
69+
70+
if re.search(r"[^/.]\.\.\.\.?|\.?\.\.\.[^/.]", path):
71+
raise ValueError("... and .... must be between slashes")
72+
73+
if "....." in path:
74+
raise ValueError("Path cannot contain more than 4 dots in a row.")
6375

6476
def matches(
6577
self, method: str, path: str

0 commit comments

Comments
 (0)