Skip to content

indent filter fails to apply indentation for large input strings #465

@strickczq

Description

@strickczq

Description:
The askama indent filter does not apply the specified indentation (4 spaces) when the input string exceeds a certain length (e.g., 10,000 characters). Instead, the output string lacks the expected indentation.

Steps to Reproduce:

  1. Create a project with the following Cargo.toml:

    [package]
    name = "indent-test"
    version = "0.1.0"
    edition = "2024"
    
    [dependencies]
    askama = { version = "0.14.0", features = ["code-in-doc"] }
  2. Use the following lib.rs:

    use askama::Template;
    
    /// ~~~askama
    /// {{ text | indent(4) }}
    /// ~~~
    #[derive(Template)]
    #[template(ext = "txt", in_doc = true)]
    pub struct IndentTest {
        text: String,
    }
    
    pub fn run(limit: usize) {
        let rendered = IndentTest {
            text: format!("a\n{}", "b".repeat(limit - 2)),
        }
        .render()
        .unwrap();
    
        assert_eq!(&rendered[0..10], "a\n    bbbb");
    }
    
    #[test]
    fn test_9999() {
        run(9999);
    }
    
    #[test]
    fn test_10000() {
        run(10000);
    }
  3. Run cargo test.

Image

Expected Behavior:
The indent filter should prepend 4 spaces to each line after the first, regardless of input size. For test_10000, the first 10 characters of the rendered output should be "a\n bbbb".

Actual Behavior:
For inputs with 9,999 characters, the output is correct ("a\n bbbb"). For 10,000 characters, the indentation is missing, resulting in "a\nbbbbbbbb".

Environment:

  • Rust edition: v1.86.0
  • Askama version: 0.14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions