From 2750a14517f9b9c84ba5533696fe4046f61e0bcc Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Thu, 12 Feb 2026 09:31:10 -0700 Subject: [PATCH 1/2] fix bug where part of template annotation line was not stripped In https://github.com/ViewComponent/view_component/pull/2541, logic was added to strip out the first template annotation line. Unfortunately, the template annotations in Rails span multiple lines, causing invalid Ruby to be eval'd. This fix splits the compiled source on ";", which properly isolates the template annotation for easy removal. --- docs/CHANGELOG.md | 4 ++-- lib/view_component/template.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4767b8efa..82e1def84 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,9 +10,9 @@ nav_order: 6 ## main -* Fix segfault when Ruby coverage is enabled but template annotations are disabled. +* Fix segfaults when Ruby coverage is enabled. - *George Holborn* + *George Holborn*, *Joel Hawksley* * Add `protocol` parameter to `with_request_url` test helper to enable testing with HTTPS protocol. diff --git a/lib/view_component/template.rb b/lib/view_component/template.rb index ba15b1dc6..23ca0c5ee 100644 --- a/lib/view_component/template.rb +++ b/lib/view_component/template.rb @@ -65,7 +65,7 @@ def compiled_source result = super # Strip the annotation line to maintain correct line numbers when coverage # is running (avoids segfault from negative lineno) - result = result.sub(/\A[^\n]*\n/, "") if @strip_annotation_line + result = result.partition(";").last if @strip_annotation_line result end end From 0e6dc1c454879f4b4dc3a58631e801b192f85abe Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Thu, 12 Feb 2026 10:28:39 -0700 Subject: [PATCH 2/2] do not assert against annotation --- test/sandbox/test/mailer_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/sandbox/test/mailer_test.rb b/test/sandbox/test/mailer_test.rb index 04f3495ea..a114a5726 100644 --- a/test/sandbox/test/mailer_test.rb +++ b/test/sandbox/test/mailer_test.rb @@ -6,7 +6,6 @@ class MailerTest < ActionMailer::TestCase def test_rendering_component_in_an_action_mailer result = TestMailer.test_email.deliver_now.body.to_s assert_includes result, "
Hello world!
" - assert_includes result, "test_email.html.erb" end def test_rendering_component_in_an_action_mailer_with_asset_component