k0kubun / hamlit

High Performance Haml Implementation
https://rubygems.org/gems/hamlit
Other
980 stars 60 forks source link

Wrong error line in template when using some filters with empty lines #160

Closed rgisiger closed 4 years ago

rgisiger commented 4 years ago

Hi,

I found a really strange issue by using :ruby filter, but I still don't know how to find properly where the issue is.

However, it seems to occur with some other filters as well as for example : :escaped, :plain or :preserve.

Ruby version 2.6.5 Hamlit version 5.1.2 Rails version 5.1.7

Errors are generated in templates like the followings :

:preserve        # or :escaped or :plain
  hello

- nil['test']
:ruby
  a = 1

- nil['test']

Thanks for investigating.

k0kubun commented 4 years ago

Hamlit version 5.1.2

This is probably Haml's version. Anyway I reproduced your issue with the latest Hamlit 2.11.0.

At a glance, :plain and :preserve are probably easy to fix, but the problem of :ruby might live in the parser brought from haml.gem. Thank you for reporting this, I'll take a closer look at this later.

rgisiger commented 4 years ago

Yes, you are right, I've put the Haml's version instead of the Hamlit one (which is the same as yours : 2.11.0)

FYI, I have Haml gem as another dependency in my project, but the funny thing about the :ruby filter is that the line position is correct when we are using only pure Haml gem.

k0kubun commented 4 years ago

Yes, I noticed that too. It knows about its own parser.

k0kubun commented 4 years ago

I almost figured out how to fix this this morning... By the filters' dynamic nature we need to count lines of filters using something like Haml::TempleLineCounter (which I added to haml :stuck_out_tongue_winking_eye:) to adjust lines after them correctly. I'll work on that after this daytime.

k0kubun commented 4 years ago

Released the fix as v2.11.1. Please try using it.