Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra whitespaces after \n in partial when rendered from a partial #613

Open
ryanolson opened this issue Sep 29, 2023 · 2 comments
Open

Comments

@ryanolson
Copy link

ryanolson commented Sep 29, 2023

version: 4.4

    #[test]
    fn test_partial_using_partial() {
        let mut handlebars = Handlebars::new();
        handlebars
            .register_partial("system", "{{#if system_prompt}}{{{system_prompt}}} {{/if}}")
            .unwrap();

        handlebars
            .register_partial("user", "User: {{>system}}{{{prompt}}}")
            .unwrap();

        let output = handlebars
            .render_template("{{>user system_prompt=\"hello\" prompt=\"world\"}}", &())
            .unwrap();

        assert_eq!(output, "User: hello world");

        let output = handlebars
            .render_template("{{>user prompt=\"world\"}}", &())
            .unwrap();

        assert_eq!(output, "User: world");

        let output = handlebars
            .render_template("{{>user}}", &json!({"system_prompt": "<<SYS>>\nhello\n<</SYS>>\n\n", "prompt": "world"}))
            .unwrap();

        assert_eq!(output, "User: <<SYS>>\nhello\n<</SYS>>\n\n world");
    }

The last assert fails. The rendered string vs the expected:

  left: `"User: <<SYS>>\n hello\n <</SYS>>\n \n world"`,
 right: `"User: <<SYS>>\nhello\n<</SYS>>\n\n world"`',
@ryanolson
Copy link
Author

playground link

@ryanolson
Copy link
Author

Note: this code works as expected using 3.5.5

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

No branches or pull requests

1 participant