Skip to content

Add support for the max filter - #1351

Open
alloutflo wants to merge 1 commit into
HubSpot:masterfrom
alloutflo:fix/672-max-filter
Open

alloutflo wants to merge 1 commit into
HubSpot:masterfrom
alloutflo:fix/672-max-filter

Conversation

@alloutflo

Copy link
Copy Markdown

Fixes #672.

{{ [1, 2, 3]|max }} currently renders nothing because the filter is not registered. Add a built-in max(case_sensitive=False, attribute=None) filter so this example renders 3.

Select the original maximum element in one pass without sorting or modifying the input; equal keys retain the first element. Support positional/named arguments, dotted attributes and list indices through the existing property resolver. Reuse Jinjava's gt coercion rules, map-iteration configuration, and case-insensitive string comparison. String iteration follows existing UTF-16 conventions. Empty/null inputs return null; invalid comparison values produce filter errors. Deferred inputs and comparison keys propagate deferral, while resolved attributes of partially deferred objects remain usable. Existing resolver restrictions, filter overrides, and disabling still apply. No dependency/configuration changes or changes to other filters.

Validation

  • The issue's regression test fails before the implementation and passes after it.
  • 27 new tests cover numeric types/large numbers, strings, stable ties and identity, attributes and resolver restrictions, invalid inputs, iterators, map settings, registration, output limits/escaping, filter-chain optimization, and eager/two-pass rendering.
  • Full Maven verify passes with Temurin 17, 21, and 25, using Maven on Java 25: 2,265 tests per run, zero failures/errors, 23 skipped. The final Java 21/25 runs use clean verify in separate checkouts of the same commit.
  • Runs use en_US for the pre-existing locale-sensitive number-format assertions. Spotless, Checkstyle, SpotBugs, PMD, diff review, and git diff --check pass.

Existing limitation

Raw DeferredValue markers nested inside Java collections can be serialized incorrectly by the existing eager reconstruction machinery. This was reproduced on untouched upstream with {{ (values|first).score }}; it is not addressed by this filter. Defer the collection itself or construct its deferred values through template expressions. Those two-pass paths are covered here.

Implemented and reviewed with assistance from OpenAI Codex.

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.

Max filter not working

1 participant