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

Unwanted whitespace in match arm #397

Closed
msrd0 opened this issue Dec 9, 2020 · 2 comments · Fixed by #399
Closed

Unwanted whitespace in match arm #397

msrd0 opened this issue Dec 9, 2020 · 2 comments · Fixed by #399
Assignees
Labels

Comments

@msrd0
Copy link
Contributor

msrd0 commented Dec 9, 2020

For a Template struct containing a field ver: Option<&'a str> and the following template:

{% let suffix -%}
{% match ver -%}
  {% when Some with (ver) -%}
    {% let suffix = format!("-{}", ver) -%}
  {% when None -%}
    {% let suffix = String::new() -%}
{% endmatch -%}

This code is part of the first match arm: writer.write_str("\n ")?;. However, since every line ends with -%}, there should't be any newlines inserted into this part of the template.

@vallentin vallentin added the bug label Dec 10, 2020
@vallentin
Copy link
Collaborator

I'm wondering where the whitespace between the match and the first when should go. Whether it should go into the first match arm or before the match expression (thus "into" all match arms). The whitespace before endmatch is self-explanatory.

In short:

{% match ... %}[this whitespace]{% when ... %}

Should it result in:

match ... {
    Some(_) => {
        writer.write_str("[this whitespace]")?;

or

writer.write_str("[this whitespace]")?;
match ... {

@djc?

@djc
Copy link
Collaborator

djc commented Dec 11, 2020

Maybe we should just skip it always? I don't think there's really a natural place for it to go.

@vallentin vallentin self-assigned this Dec 11, 2020
vallentin added a commit to vallentin/askama that referenced this issue Dec 12, 2020
vallentin added a commit that referenced this issue Dec 12, 2020
* Fixed #397

* Updated parser to ignore whitespace between match and when

* Updated test cases

* Updated Python script to generate match ws tests

* Added match ws tests

* Resolved rustfmt lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants