Skip to content
New issue

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

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

Already on GitHub? # to your account

Text within {% raw %} is being jumbled when it contains multiple liquid variables #79

Closed
epage opened this issue Feb 27, 2017 · 2 comments
Labels
bug Not as expected

Comments

@epage
Copy link
Member

epage commented Feb 27, 2017

The cobalt website has this line:
{% raw %} <a href="{{post.path}}">{{ post.title }}</a>{% endraw %}
See https://github.com/cobalt-org/cobalt-org.github.io/blob/source/docs/pages.liquid#L78

That is being rendered as
</a>{{ post.title }}">{{post.path}} <a href="
See https://github.com/cobalt-org/cobalt-org.github.io/blob/master/docs/pages.html#L110

@epage epage added the bug Not as expected label May 5, 2017
@booyaa
Copy link

booyaa commented Jun 15, 2017

I was about to file a bug when I found this issue. It's reversing the order of the escaped items.

test code

use liquid::{Renderable, Context, Value};

let template = liquid::parse(
r"{% raw %}
{{ abc }}
{{ def }}
{{ ghi }}
{% endraw %}", Default::default()).unwrap();

let mut context = Context::new();
context.set_val("num", Value::Num(4f32));

let output = template.render(&mut context);
assert_eq!(output.unwrap(), Some("\n{{ abc }}\n{{ def }}\n{{ ghi }}\n".to_string()));

I'm going to have a go a see if I can fix it!

@booyaa
Copy link

booyaa commented Jun 23, 2017

I'm getting a bit confused, I thought this was a fault with the raw block, but my latest findings would indicate otherwise.

I jumped straight into the raw block code and added a new test that should fail.

#[test]
fn test_raw_ordered() {
    use std::default::Default;

    let options: LiquidOptions = Default::default();
    let raw = raw_block("raw",
                        &[],
                        &vec![Expression(vec![], "{{abc}}\n{{def}}\n{{ghi}}".to_owned())],
                        &options);
    assert_eq!(raw.unwrap().render(&mut Default::default()).unwrap(),
               Some("{{abc}}\n{{def}}\n{{ghi}}".to_owned()));
}

It didn't fail, it passed!

Yet my test code still fails. I've cleaned up the code from last update.

fn main() {
    use liquid::Renderable;

    let template = liquid::parse(r"{% raw %}
{{ abc }}
{{ def }}
{{ ghi }}
{% endraw %}", Default::default()).unwrap();

    let output = template.render(&mut Default::default());
    assert_eq!(output.unwrap(),
               Some("\n{{ abc }}\n{{ def }}\n{{ ghi }}\n".to_string()));
}

Wondering I should look next? I'm thinking the parser or render calls?

epage added a commit to epage/liquid-rust that referenced this issue Dec 26, 2017
epage added a commit that referenced this issue Dec 27, 2017
* **parse:**  Error on empty expressions ([5cffe44](5cffe44), closes [#139](#139))
* **raw:**  Stop swapping the text's order ([bd45c14](bd45c14), closes [#79](#79))
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Not as expected
Projects
None yet
Development

No branches or pull requests

2 participants