Skip to content

fix(jinja): reject slices with a zero step - #2890

Open
smg99 wants to merge 1 commit into
huggingface:mainfrom
smg99:fix/jinja-zero-slice-step
Open

smg99 wants to merge 1 commit into
huggingface:mainfrom
smg99:fix/jinja-zero-slice-step

Conversation

@smg99

@smg99 smg99 commented Nov 19, 2026 •

Copy link
Copy Markdown

{{ value[::0] }} currently silently renders an empty slice. Python/Jinja rejects this invalid step, even for empty lists and strings.

Reject zero in the shared slice helper and cover empty/nonempty lists and strings through the public Template.render() API. This is separate from the reverse-slice bounds fix in #2691.

Validation: 768 tests pass across the templates, utilities, interpreter, formatting, and memory suites; Jinja build (including TypeScript declarations), ESLint, formatting, and git diff --check pass. The new zero-step regression fails before the change.

The model-download e2e suite is excluded: this checkout lacks a built @huggingface/hub workspace dependency.


Note

Low Risk
Narrow behavioral fix for invalid slice syntax with regression tests; no auth, data, or infrastructure impact.

Overview
Jinja slice behavior now matches Python for zero step: templates using {{ value[::0] }} throw "slice step cannot be zero" instead of rendering an empty slice.

The shared slice() helper in utils.ts performs the guard (consistent with existing range() validation). New regression tests exercise empty/non-empty lists and strings through Template.render().

Reviewed by Cursor Bugbot for commit 622c470. Bugbot is set up for automated code reviews on this repo. Configure here.

@smg99
smg99 requested a review from xenova as a code owner November 19, 2026 05:27
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.

1 participant