Skip to content

Commit

Permalink
fix(autofix): make HTML cleanup honor ignore flag
Browse files Browse the repository at this point in the history
Once the check is ignored on the string, the cleanup should also not
happen.

Fixes #13544
  • Loading branch information
nijel committed Jan 16, 2025
1 parent d24f47c commit 5054173
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Not yet released.
**Bug fixes**

* Fixed translations caching in :ref:`machine-translation-setup`.
* :ref:`autofix-html` automatic fixups honors the ``ignore-safe-html`` flag.

**Compatibility**

Expand Down
2 changes: 1 addition & 1 deletion weblate/trans/autofixes/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_related_checks():

def fix_single_target(self, target: str, source: str, unit):
flags = unit.all_flags
if "safe-html" not in flags:
if "safe-html" not in flags or "ignore-safe-html" in flags:
return target, False

sanitizer = HTMLSanitizer()
Expand Down
10 changes: 10 additions & 0 deletions weblate/trans/tests/test_autofix.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ def test_html(self) -> None:
(["%(percent)s %%"], False),
)

def test_html_ignored(self) -> None:
fix = BleachHTML()
unit = MockUnit(
source='<a href="script:foo()">link</a>', flags="safe-html,ignore-safe-html"
)
self.assertEqual(
fix.fix_target(["Allow <b>"], unit),
(["Allow <b>"], False),
)

def test_html_markdown(self) -> None:
fix = BleachHTML()
unit = MockUnit(
Expand Down

0 comments on commit 5054173

Please sign in to comment.