Skip to content

Commit

Permalink
Make circular symlink error dependent on OS and Python version
Browse files Browse the repository at this point in the history
  • Loading branch information
steverep committed Jul 17, 2024
1 parent 4336e33 commit 213199d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import keyword
import os
import re
import sys
from contextlib import contextmanager
from pathlib import Path
from types import MappingProxyType
Expand Down Expand Up @@ -75,6 +76,12 @@
else:
BaseDict = dict

CIRCULAR_SYMLINK_ERROR = (
OSError
if sys.version_info < (3, 10) and sys.platform.startswith("win32")
else RuntimeError
)

YARL_VERSION: Final[Tuple[int, ...]] = tuple(map(int, yarl_version.split(".")[:2]))

HTTP_METHOD_RE: Final[Pattern[str]] = re.compile(
Expand Down Expand Up @@ -665,8 +672,7 @@ def _resolve_path_to_response(self, unresolved_path: Path) -> StreamResponse:
else:
file_path = unresolved_path.resolve()
file_path.relative_to(self._directory)
# TODO(PY39): Remove OSError needed to appease 3.8 on Windows.
except (ValueError, RuntimeError, OSError) as error:
except (ValueError, CIRCULAR_SYMLINK_ERROR) as error:
# ValueError for relative check; RuntimeError for circular symlink.
raise HTTPNotFound() from error

Expand Down

0 comments on commit 213199d

Please sign in to comment.