Mustache.ex icon indicating copy to clipboard operation
Mustache.ex copied to clipboard

Escape characters using triple brackets

Open yordis opened this issue 7 years ago • 0 comments

I have this test

template_attrs = %{
  # notice here how I print `partials.marketing_text`
  html_body:
    "<b>Welcome</b> {{data.username}}!, enjoy a good reputation, {{partials.marketing_text}}",
  text_body:
    "Welcome {{data.username}}!, enjoy a good reputation, {{partials.marketing_text}}"
}

partial_attrs = %{
  name: "marketing_text",
  html: "<b>Purchase Now!</b>: {{data.address}}",
  text: "Purchase Now!: {{data.address}}"
}

template = insert(:template, template_attrs)
partial = insert(:partial, partial_attrs)

assert {:ok, template} = Template.add_partials(template, [partial])

{:ok, email} =
  @from
  |> Email.new(@to)
  |> Email.with_template(template.name, @options)

assert email.html_body ==
         "<b>Welcome</b> tokarev!, enjoy a good reputation, <b>Purchase Now!</b>: POBOX 54634"

assert email.text_body ==
         "Welcome tokarev!, enjoy a good reputation, Purchase Now!: POBOX 54634"

What I need you to notice from here is that I have this code

  html_body:
    "<b>Welcome</b> {{data.username}}!, enjoy a good reputation, {{partials.marketing_text}}",

Where basically I take the html rendered text of the partial and renderer in that section.

The issue is this one.

This code should fail because only when I use {{{partials.marketing_text}}} is when the html should be escaped.

yordis avatar Jan 01 '18 23:01 yordis