From b3490d036d1a6ebb43e9c41ff9a51800924bd089 Mon Sep 17 00:00:00 2001 From: Nick Smith Date: Wed, 23 Sep 2020 14:57:44 +0100 Subject: [PATCH] Add data- attributes to GOOD_STRINGS Boolean data attributes (e.g. data-foo) should not be translated, whereas those which take values (data-title="foo") should be. --- django_template_i18n_lint.py | 2 +- tests.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/django_template_i18n_lint.py b/django_template_i18n_lint.py index 9503b59..453758a 100755 --- a/django_template_i18n_lint.py +++ b/django_template_i18n_lint.py @@ -63,7 +63,7 @@ def location(str, pos): |(?:['"]\W+)?(?:data-|data-original-)?(?:alt|value|title|summary)=['"]? # Boolean attributes - |<[^<>]+?(?:checked|selected|disabled|readonly|multiple|ismap|defer|async|declare|noresize|nowrap|noshade|compact|hidden|itemscope|autofocus|autoplay|controls|download)[^<>]*?> + |<[^<>]+?(?:checked|selected|disabled|readonly|multiple|ismap|defer|async|declare|noresize|nowrap|noshade|compact|hidden|itemscope|autofocus|autoplay|controls|download|data-(?:(?!=)[a-z-]+(?=[<> /]))+)[^<>]*?> # HTML opening tag |<[\w:]+ diff --git a/tests.py b/tests.py index 0c9f25f..628d930 100644 --- a/tests.py +++ b/tests.py @@ -33,6 +33,8 @@ class DjangoTemplateI18nLintTestCase(unittest.TestCase): testDjangoVar = _known_good_output("Foo{{ bar }}Baz", [(1, 1, 'Foo'), (1, 13, 'Baz')]) testBooleanValuesOK1 = _known_good_output("",[(1, 18, 'Option')]) testBooleanValuesOK2 = _known_good_output("",[]) + testBooleanValuesOK3 = _known_good_output("",[]) + testBooleanValuesOK4 = _known_good_output("",[]) testNoHTMLAttrSingleQuote = _known_good_output("
FOO
", [(1, 21, 'FOO')]) testNoHTMLAttrDoubleQuote = _known_good_output("
FOO
", [(1, 21, 'FOO')])