diff --git a/dennis/linter.py b/dennis/linter.py index 350b6db..5d9b0a8 100644 --- a/dennis/linter.py +++ b/dennis/linter.py @@ -1,4 +1,5 @@ import re +import uuid from collections import namedtuple from itertools import zip_longest @@ -195,16 +196,25 @@ def lint(self, vartok, linted_entry): return [] malformed_re = re.compile(r"(?:(?:^|\})[^\{]*\})") + double_open = str(uuid.uuid4()) + double_close = str(uuid.uuid4()) for trstr in linted_entry.strs: if not trstr.msgstr_string: continue - malformed = malformed_re.findall(trstr.msgstr_string) + malformed = malformed_re.findall( + trstr.msgstr_string.replace("{{", double_open).replace( + "}}", double_close + ) + ) if not malformed: continue - malformed = [item.strip() for item in malformed] + malformed = [ + item.strip().replace(double_open, "{{").replace(double_close, "}}") + for item in malformed + ] msgs.append( LintMessage( ERROR, diff --git a/tests/test_linter.py b/tests/test_linter.py index b5f44c5..28661da 100644 --- a/tests/test_linter.py +++ b/tests/test_linter.py @@ -335,6 +335,15 @@ def test_python_var_missing_left_curly_brace(self): assert msgs[0].code == "E103" assert msgs[0].msg == "missing left curly-brace: }}" + def test_double_braces(self): + linted_entry = build_linted_entry( + 'msgid "This is {{literal}} brace, {0}, and {{another}}."\n' + 'msgstr "This is {{literal}} brace, {0}, and {{another}}."\n' + ) + + msgs = self.lintrule.lint(self.vartok, linted_entry) + assert len(msgs) == 0 + def test_varformat_empty(self): vartok = VariableTokenizer([])