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

String interpolation in tags nested in variables does not work #55

Open
MajronMan opened this issue Aug 18, 2017 · 8 comments
Open

String interpolation in tags nested in variables does not work #55

MajronMan opened this issue Aug 18, 2017 · 8 comments
Labels

Comments

@MajronMan
Copy link

Environment:

  • Erlang/OTP 20
  • Elixir 1.5.1
  • Phoenix 1.3.0
  • Phoenix HTML 2.10.4
  • Phoenix Slime 0.9.0
  • Slime 0.16.0
  • System 4.12.8-1-ARCH

Expected behaviour

String interpolation in input value works like without interpolation, e.g.

- foo = "bar"

- form_ok = Phoenix.HTML.Tag.content_tag(:form) do
  input name="test" value="val"

p "#{foo}"

= form_ok

Renders

<p>bar</p>
<form>
  <input name="test" value="val">
</form>

Actual behaviour

- foo = "bar"

- form_not_ok = Phoenix.HTML.Tag.content_tag(:form) do
  input name="test" value="#{foo}"

p "#{foo}"

= form_not_ok

Renders

<input name="test"<p>bar</p>
<form>
  <input name="test" value="bar">
</form>     
@doomspork
Copy link
Member

doomspork commented Aug 23, 2017

@MajronMan it may be that I don't have much ☕️ in me yet but are these two examples not different? The first doesn't appear to include interpolation.

Do you have code somewhere I can peek at? If not, I'll try to throw together a simple Slime application (sans Phoenix) and see if we can narrow it down. @Rakoth I think this may be an issue with the parser, wanted to give you a heads up 👍

@MajronMan
Copy link
Author

@doomspork You might be right and it's not a perfect example, I just wanted to show that the case is certainly the interpolation since it's the only difference between those two pieces of code.

I stumbled upon this bug in rather complex circumstances and I doubt they are worth describing in detail, but the main idea was to reuse a form created by my own function (to add CSRF token etc.) with inputs populated with values passed to the template by Phoenix View's assigns. Investigation enabled me to produce this simple example above.

@doomspork
Copy link
Member

@MajronMan do you have that code public?

@Rakoth
Copy link
Member

Rakoth commented Aug 23, 2017

@MajronMan Hi! Could you reproduce this issue with slime 1.0?

@MajronMan
Copy link
Author

@doomspork Unfortunately I can't share this code :(

@Rakoth I don't know how to do it without using Phoenix Tag and I used this library, but I will try to do so tomorrow (I am in different timezone so it's evening for me)

@Rakoth
Copy link
Member

Rakoth commented Aug 24, 2017

@MajronMan you could just add {:slime, "~> 1.0", override: true} into your project's deps

@MajronMan
Copy link
Author

@Rakoth I created a repo with slime 1.0 and the bug is still there
https://github.com/MajronMan/slime_bug

@Rakoth
Copy link
Member

Rakoth commented Aug 24, 2017

Thanks @MajronMan it helped a lot! I narrowed it down to a very strange behaviour of EEx:

<h1>header</h1>
<% foo = "bar" %>
<% form_not_ok = Phoenix.HTML.Tag.content_tag(:form) do %>
  test
  <% a = "baz" %>
  <div id="<%= a %>"></div>
<% end %>
<%= form_not_ok %>

renders to

  test
<form>
  test
  <div id="baz"></div>
</form>

Note repeated test string and missing <h1>. There is some problem with <% a = "baz" %> part.
Since Slime uses eex representation underhood and attribute interpolation code compiles to similar eex template we are affected by this issue.
I will try to find a workaround for this case.

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

No branches or pull requests

3 participants