Skip to content

AI spam#2198

Closed
lin-hongkuan wants to merge 1 commit into
pallets:mainfrom
lin-hongkuan:codex/indent-empty-input-first-blank
Closed

AI spam#2198
lin-hongkuan wants to merge 1 commit into
pallets:mainfrom
lin-hongkuan:codex/indent-empty-input-first-blank

Conversation

@lin-hongkuan

Copy link
Copy Markdown

indent(first=True) currently prefixes the indent string even when the filter input is empty and blank is left as False. That produces whitespace for an otherwise empty filtered block.

This returns the empty input unchanged when blank lines are not being indented, while keeping existing behavior for non-empty multiline input. It also adds coverage for direct empty-string filtering and an empty {% filter indent(first=true) %} block.

fixes #2176

Tests:

  • python -m pytest tests\\test_filters.py -q
  • python -m pytest -q
  • python -m ruff check src\\jinja2\\filters.py tests\\test_filters.py
  • python -m ruff format --check src\\jinja2\\filters.py tests\\test_filters.py
  • python -m mypy src\\jinja2\\filters.py
  • git diff --check

@davidism davidism closed this Jun 24, 2026
@davidism davidism changed the title Do not indent empty strings with indent first AI spam Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

indent filter ignores blank=False when first=True on first line

2 participants