-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CMK-17499
- Loading branch information
Showing
6 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import re | ||
|
||
# keep in sync with tests/pylint/checker_localization.py:HTMLTagsChecker | ||
_TAG_PATTERN = re.compile("<.*?>") | ||
_ALLOWED_TAGS_PATTERN = re.compile( | ||
r"</?(h1|h2|b|tt|i|u|hr|br(?: /)?|nobr(?: /)?|pre|sup|p|li|ul|ol|a|(a.*? href=.*?))>" | ||
) | ||
|
||
|
||
def forbidden_tags(text: str) -> set[str]: | ||
return { | ||
tag | ||
for tag in re.findall( | ||
_TAG_PATTERN, | ||
text, | ||
) | ||
if not re.match(_ALLOWED_TAGS_PATTERN, tag) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import pytest | ||
|
||
from checkmk_weblate_syncer.html_tags import forbidden_tags | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["text", "expected_result"], | ||
[ | ||
pytest.param( | ||
"abc123", | ||
frozenset(), | ||
), | ||
pytest.param( | ||
"<tt>bold</tt>", | ||
frozenset(), | ||
), | ||
pytest.param( | ||
'* ? <a href="%s">%s</a>', | ||
frozenset(), | ||
), | ||
pytest.param( | ||
'© <a target="_blank" href="https://checkmk.com">Checkmk GmbH</a>', | ||
frozenset(), | ||
), | ||
pytest.param( | ||
"123 <script>injection</script>", | ||
frozenset( | ||
["<script>", "</script>"], | ||
), | ||
), | ||
pytest.param( | ||
# pylint: disable=line-too-long | ||
"""#: /home/weblate/checkmk_weblate_sync/git/checkmk/cmk/gui/wato/pages/host_rename.py:640 | ||
#, python-format | ||
msgid " (%d times)" | ||
msgstr "" | ||
#: /home/weblate/checkmk_weblate_sync/git/checkmk/cmk/gui/visuals/_page_edit_visual.py:137 | ||
msgid " (Copy)" | ||
msgstr "" | ||
#: /home/weblate/checkmk_weblate_sync/git/checkmk/cmk/gui/nodevis/topology.py:1814 | ||
msgid " (Data incomplete, maximum number of nodes reached)" | ||
msgstr "" | ||
#: /home/weblate/checkmk_weblate_sync/git/checkmk/cmk/gui/backup/handler.py:969 | ||
#, python-format | ||
msgid " (Duration: %s)" | ||
msgstr "" | ||
""", | ||
frozenset(), | ||
), | ||
], | ||
) | ||
def test_html_tags_checker( | ||
text: str, | ||
expected_result: frozenset[str], | ||
) -> None: | ||
assert forbidden_tags(text) == expected_result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters