Skip to content

Commit

Permalink
Reproduce bug djc#1075: rendering nested block broken by if-else-endi…
Browse files Browse the repository at this point in the history
…f in outer block
  • Loading branch information
clonejo committed Aug 3, 2024
1 parent 5a83872 commit cd9bc37
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions testing/templates/fragment-nested-block-bug-if-else-endif.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "fragment-base.html" %}

{% block body %}
{% if true %}
true
{% else %}
false
{% endif %}
{% block nested %}
<p>I should be here.</p>
{% endblock %}
{% endblock %}
21 changes: 21 additions & 0 deletions testing/tests/block_fragments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ fn test_fragment_nested_block() {
);
}

#[derive(Template)]
#[template(
path = "fragment-nested-block-bug-if-else-endif.html",
block = "nested"
)]
struct FragmentNestedBlockBugIfElseEndif;

/// Reproduce bug https://github.com/djc/askama/issues/1075
/// When if-else-endif appears outside the rendered block, Buffer::dedent() would error with
/// "dedent() called while indentation == 0".
/// The same happens with endif and if, if they are on the same row.
#[test]
fn test_fragment_nested_block_bug_if_else_endif() {
let nested_block = FragmentNestedBlockBugIfElseEndif {};

assert_eq!(
nested_block.render().unwrap(),
"\n<p>I should be here.</p>\n"
);
}

#[derive(Template)]
#[template(path = "fragment-nested-super.html", block = "body")]
struct FragmentNestedSuper<'a> {
Expand Down

0 comments on commit cd9bc37

Please sign in to comment.