Skip to content

Commit

Permalink
Update formatter to avoid reporting paths with .. (#3496)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed May 25, 2023
1 parent ce1a030 commit b2767d2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ansiblelint/formatters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def _format_path(self, path: str | Path) -> str | Path:
if not self.base_dir or not path:
return path
# Use os.path.relpath 'cause Path.relative_to() misbehaves
return os.path.relpath(path, start=self.base_dir)
rel_path = os.path.relpath(path, start=self.base_dir)
# Avoid returning relative paths that go outside of base_dir
if rel_path.startswith(".."):
return path
return rel_path

def apply(self, match: MatchError) -> str:
"""Format a match error."""
Expand Down

0 comments on commit b2767d2

Please sign in to comment.