Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/serena/tools/file_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def apply(self, relative_path: str, content: str) -> str:
if will_overwrite_existing:
self.project.validate_relative_path(relative_path, require_not_ignored=True)
else:
assert abs_path.is_relative_to(self.get_project_root()), (
f"Cannot create file outside of the project directory, got {relative_path=}"
)
# Use the always-on containment guard rather than a bare `assert`, which is
# compiled out under `python -O` / PYTHONOPTIMIZE and would otherwise leave the
# new-file branch with no path-containment check.
self.project.validate_relative_path(relative_path)

# writing the file
abs_path.parent.mkdir(parents=True, exist_ok=True)
Expand Down