Skip to content

Emit an error if an extends block doesn't come first in a template#584

Merged
GuillaumeGomez merged 2 commits intoaskama-rs:masterfrom
GuillaumeGomez:extends-first
Aug 25, 2025
Merged

Emit an error if an extends block doesn't come first in a template#584
GuillaumeGomez merged 2 commits intoaskama-rs:masterfrom
GuillaumeGomez:extends-first

Conversation

@GuillaumeGomez
Copy link
Copy Markdown
Collaborator

Fixes #164.

@GuillaumeGomez GuillaumeGomez force-pushed the extends-first branch 2 times, most recently from 999c21e to c2e4718 Compare August 24, 2025 20:01
@Kijewski
Copy link
Copy Markdown
Member

I moved the test out of Node::many(), so instances of {% block my_block %}{% extends ".." %}{% endblock %} get rejected by the parser, not only in derive.

Copy link
Copy Markdown
Member

@Kijewski Kijewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Please review my change before merging. :)

Comment thread askama_parser/src/node.rs Outdated
let mut nb_nodes = 0;

repeat(0.., move |i: &mut _| Self::parse_nodes(i, &mut nb_nodes))
.map(|v: Vec<_>| v)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember why this "custom type ascription" was needed, but I'm happy that it isn't anymore!

@GuillaumeGomez
Copy link
Copy Markdown
Collaborator Author

Your changes look good, thanks! :)

As a follow-up, would be nice to add a regression test for the extends in blocks too.

@GuillaumeGomez GuillaumeGomez merged commit 5c4b52a into askama-rs:master Aug 25, 2025
51 checks passed
@GuillaumeGomez GuillaumeGomez deleted the extends-first branch August 25, 2025 10:28
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.

Warn when content in extends child

2 participants