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

Haml on JRuby 9.2.0.0 throws error evaluating interpolated element attribute with # #5210

Closed
HarlemSquirrel opened this issue Jun 6, 2018 · 4 comments
Milestone

Comments

@HarlemSquirrel
Copy link

Interesting issue with JRuby 9.2.0.0 and Haml when attempting to evaluate an element attribute with a # just before the interpolated variable.

This is the line which causes the error.

-# app/views/welcome/_partial.html.haml
%p{ data: { target: "##{partial_local_var}" } }
Error:
WelcomesTest#test_visiting_the_index:
ActionView::Template::Error: undefined local variable or method `partial_local_var' for #<Haml::AttributeCompiler:0x9906d99>
    (eval):1:in `<eval>'
    app/views/welcome/index.html.erb:3:in `_app_views_welcome_index_html_erb___706324677_2068'

Using %p{ data: { target: ('#' + partial_local_var.to_s) } } does not throw the error.

I made a test app to demonstrate the error.

@HarlemSquirrel
Copy link
Author

HarlemSquirrel commented Jun 6, 2018

Actually, I was able to make a much smaller test case. Too bad I didn't think of this before making the whole Rails app.

-# test.haml
- time = Time.now
%p{ 'data-time': "##{time}" } Time
➤  rvm use jruby-9.2.0.0 do haml test.haml 
Exception on line 1: undefined local variable or method `time' for #<Haml::AttributeCompiler:0x144a5e6e>
  Use --trace for backtrace.

➤  rvm use jruby-9.1.17.0 do haml test.haml                                                                                     1 ↵
<p data-time='#2018-06-06 13:04:38 -0400'>Time</p>

➤  rvm use 2.5.1 do haml test.haml
<p data-time='#2018-06-06 13:04:45 -0400'>Time</p>

Adding a space between # and the interpolation does not raise the error.

-# test.haml
- time = Time.now
%p{ 'data-time': "# #{time}" } Time
➤  rvm use jruby-9.2.0.0 do haml test.haml 
<p data-time='# 2018-06-06 13:07:11 -0400'>Time</p>

@HarlemSquirrel HarlemSquirrel changed the title Haml on JRuby 9.2.0.0 throws error when evaluating interpolated element attribute Haml on JRuby 9.2.0.0 throws error evaluating interpolated element attribute with # Jun 6, 2018
@headius
Copy link
Member

headius commented Jun 11, 2018

Neato...so it's having a problem with the double # here. Maybe a simple fix @enebo?

@headius headius added this to the JRuby 9.2.1.0 milestone Jun 11, 2018
@enebo
Copy link
Member

enebo commented Jun 12, 2018

Maybe not simple at all... :) It took a while to trace this to Temple using Ripper.

I did just reduce it to a ripper bug though. Here is a minimized test case:

jruby -rripper -e "p Ripper.lex('\"##{time}\"')"

We should be seeing to_tstring_content of just '#', but instead we slurp in '##{time}'. Getting close.

@enebo enebo closed this as completed in 84dcb31 Jun 12, 2018
@HarlemSquirrel
Copy link
Author

Nice work!

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

3 participants