Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rich exception with tasks containing square brackets #2510

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ansiblelint/formatters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def format(self, match: MatchError) -> str:
f"[filename]{self._format_path(match.filename or '')}[/]:{match.position}"
)
if match.details:
result += f" [dim]{match.details}[/]"
result += f" [dim]{self.escape(str(match.details))}[/]"
result += "\n"
return result

Expand Down
6 changes: 4 additions & 2 deletions test/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
rule = AnsibleLintRule()
rule.id = "TCF0001"
formatter = Formatter(pathlib.Path.cwd(), display_relative_path=True)
# These details would generate a rich rendering error if not escaped:
DETAILS = "Some [/tmp/foo] details."


def test_format_coloured_string() -> None:
"""Test formetting colored."""
match = MatchError(
message="message",
linenumber=1,
details="hello",
details=DETAILS,
filename=Lintable("filename.yml"),
rule=rule,
)
Expand All @@ -47,7 +49,7 @@ def test_unicode_format_string() -> None:
match = MatchError(
message="\U0001f427",
linenumber=1,
details="hello",
details=DETAILS,
filename=Lintable("filename.yml"),
rule=rule,
)
Expand Down