Skip to content

Engine: Preserve line count for ERB comment lines#1555

Open
joelhawksley wants to merge 7 commits intomarcoroth:mainfrom
joelhawksley:fix/erb-comment-line-preservation
Open

Engine: Preserve line count for ERB comment lines#1555
joelhawksley wants to merge 7 commits intomarcoroth:mainfrom
joelhawksley:fix/erb-comment-line-preservation

Conversation

@joelhawksley
Copy link
Copy Markdown
Contributor

ERB comment lines (<%# ... %>) were stripped from compiled output, producing fewer lines than Erubi. This causes misattributed error locations when compiled templates are evaluated with module_eval and a line offset.

Erubi emits a blank line for each comment, preserving line numbering. Herb stripped them entirely.

Fix: Emit a blank code line ([:code, "\n", ...]) when processing standalone ERB comments at line start.

ERB comment lines (`<%# ... %>`) were stripped from compiled output,
producing fewer lines than Erubi. This line count difference causes
misattributed error locations and can affect error handling at template
boundaries when compiled templates are evaluated with module_eval and
a line offset.

Erubi emits a blank line for each comment, preserving line numbering:

    Template: `<%# comment %>\n<% code %>`
    Erubi:    `\n code ;\n` (2 lines)
    Herb:     ` code \n`    (1 line - WRONG)

Fix: Emit a blank code line (`[:code, "\n", ...]`) when processing
standalone ERB comments at line start.
@joelhawksley joelhawksley marked this pull request as draft March 31, 2026 16:48
@joelhawksley
Copy link
Copy Markdown
Contributor Author

joelhawksley commented Mar 31, 2026

Moving back to draft mode while I re-validate against 0.9.3.

@joelhawksley joelhawksley marked this pull request as ready for review March 31, 2026 17:17
@marcoroth marcoroth changed the title Preserve line count for ERB comment lines Engine: Preserve line count for ERB comment lines Mar 31, 2026
@marcoroth
Copy link
Copy Markdown
Owner

@joelhawksley I'm happy to merge this, but just want to understand: The evaluated output was already correct and this is about more about "cosmetics", right?

@marcoroth
Copy link
Copy Markdown
Owner

Actually, does Erubi really try to make an effort to keep the code on the same line as it was in the source?

@joelhawksley
Copy link
Copy Markdown
Contributor Author

@marcoroth As it turns out, we didn't need this change to pass CI. We are green on 0.9.4! I still think it's a good idea though, as it's nice to have error messages raised on the same lines as the original template file.

@marcoroth
Copy link
Copy Markdown
Owner

@joelhawksley awesome, that's great to hear and thanks for sharing! 🎉

I agree, it would be nice to have it aligned and behave the same way. Is there a reason why you closed #1556? Doesn't that serve a similar purpose?

@joelhawksley
Copy link
Copy Markdown
Contributor Author

@marcoroth I closed #1556 because I didn't need it to pass CI. I left this one open because you commented on it ❤️

I'll let you decide whether to take any of them 😄

@marcoroth
Copy link
Copy Markdown
Owner

Oh my bad then, I only commented on one because they looked so similar. But if #1556 is actually also valid on its own then lets re-open it 🙌🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants