From 183a7c0a5d7f0fc829ab8f7252c4b84e07692d4d Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Mon, 18 Sep 2023 09:27:31 +0200 Subject: [PATCH] fix(formatter): fixed formatting on functions that used python keywords as the param name closes #756 --- src/djlint/formatter/indent.py | 5 ++++- tests/test_nunjucks/test_functions.py | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/djlint/formatter/indent.py b/src/djlint/formatter/indent.py index 9c4709a47..fa0ccf47c 100644 --- a/src/djlint/formatter/indent.py +++ b/src/djlint/formatter/indent.py @@ -344,7 +344,10 @@ def format_data(config: Config, contents: str, tag_size: int, leading_space) -> except: # was not json.. try to eval as set try: - evaluated = str(eval(contents)) + # if contents is a python keyword, do not evaluate it. + evaluated = ( + str(eval(contents)) if contents not in ["object"] else contents + ) # need to unwrap the eval contents = ( evaluated[1:-1] diff --git a/tests/test_nunjucks/test_functions.py b/tests/test_nunjucks/test_functions.py index 49cb4070f..67da67fe3 100644 --- a/tests/test_nunjucks/test_functions.py +++ b/tests/test_nunjucks/test_functions.py @@ -131,6 +131,13 @@ ({}), id="broken", ), + pytest.param( + ("{{ url(object) }}"), + # https://github.com/Riverside-Healthcare/djLint/issues/756 + ("{{ url(object) }}\n"), + ({}), + id="function param is python keyword", + ), ]