Skip to content

Commit b2767d2

Browse files
authored
Update formatter to avoid reporting paths with .. (#3496)
1 parent ce1a030 commit b2767d2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/ansiblelint/formatters/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ def _format_path(self, path: str | Path) -> str | Path:
4242
if not self.base_dir or not path:
4343
return path
4444
# Use os.path.relpath 'cause Path.relative_to() misbehaves
45-
return os.path.relpath(path, start=self.base_dir)
45+
rel_path = os.path.relpath(path, start=self.base_dir)
46+
# Avoid returning relative paths that go outside of base_dir
47+
if rel_path.startswith(".."):
48+
return path
49+
return rel_path
4650

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

0 commit comments

Comments
 (0)