Skip to content

Commit

Permalink
Fix rich exception with tasks containing square brackets (ansible#2510)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Oct 4, 2022
1 parent 8dfa3dc commit e1b398b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
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

0 comments on commit e1b398b

Please sign in to comment.