Skip to content
Closed

AI spam #2183

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/jinja2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ def do_indent(
indention = Markup(indention)
newline = Markup(newline)

is_empty = not s
s += newline # this quirk is necessary for splitlines method

if blank:
Expand All @@ -860,7 +861,7 @@ def do_indent(
indention + line if line else line for line in lines
)

if first:
if first and (not is_empty or blank):
rv = indention + rv

return rv
Expand Down
4 changes: 4 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ def test_indent(self, env):
t = env.from_string('{{ "jinja"|indent(blank=true) }}')
assert t.render() == "jinja"

def test_indent_empty_string_with_first(self, env):
t = env.from_string('{{ ""|indent(first=true) }}')
assert t.render() == ""

def test_indent_markup_input(self, env):
"""
Tests cases where the filter input is a Markup type
Expand Down
Loading