Skip to content

Commit

Permalink
weird
Browse files Browse the repository at this point in the history
  • Loading branch information
euri10 committed Aug 30, 2024
1 parent 4a2a15f commit 6e6af22
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion litestar/middleware/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ def build_exclude_path_pattern(

try:
pattern = re.compile("|".join(exclude)) if isinstance(exclude, list) else re.compile(exclude)
if pattern.match("/"):
if pattern.match("/") and exclude != "^/$":
warn_middleware_excluded_on_all_routes(pattern, middleware_cls=middleware_cls)
return pattern

except re.error as e: # pragma: no cover
raise ImproperlyConfiguredException(
"Unable to compile exclude patterns for middleware. Please make sure you passed a valid regular expression."
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_middleware/test_base_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def third_handler() -> dict:
assert "test" in response.headers


@pytest.mark.parametrize("excludes", ["/", ["/", "/foo"], "/*"])
@pytest.mark.parametrize("excludes", ["/", ["/", "/foo"], "/*", "/.*"])
def test_exclude_by_pattern_warns_if_exclude_all(excludes: Union[str, List[str]]) -> None:
class SubclassMiddleware(AbstractMiddleware):
exclude = excludes
Expand Down

0 comments on commit 6e6af22

Please sign in to comment.