Return ``True`` when *path* escapes *project_root* or any component is a symlink. Walks the components strictly between *project_root* and *path* (including the final one) and reports whether any of them is a symlink. Components that do not exist yet are not symlinks, so this safely han
(path: Path, project_root: Path)
| 161 | |
| 162 | |
| 163 | def _has_symlinked_component(path: Path, project_root: Path) -> bool: |
| 164 | """Return ``True`` when *path* escapes *project_root* or any component is a symlink. |
| 165 | |
| 166 | Walks the components strictly between *project_root* and *path* |
| 167 | (including the final one) and reports whether any of them is a symlink. |
| 168 | Components that do not exist yet are not symlinks, so this safely handles |
| 169 | a not-yet-created destination. *project_root* itself is trusted and never |
| 170 | checked. A *path* outside *project_root* is treated as unsafe. |
| 171 | """ |
| 172 | try: |
| 173 | relative = path.relative_to(project_root) |
| 174 | except ValueError: |
| 175 | return True |
| 176 | current = project_root |
| 177 | for part in relative.parts: |
| 178 | current = current / part |
| 179 | if current.is_symlink(): |
| 180 | return True |
| 181 | return False |
| 182 | |
| 183 | |
| 184 | def _is_safe_legacy_dir(path: Path, project_root: Path) -> bool: |
no outgoing calls
no test coverage detected