Skip to content

Commit c6f7212

Browse files
committed
fix bug where part of template annotation line was not stripped
In #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.
1 parent 5ded019 commit c6f7212

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

docs/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ nav_order: 6
1010

1111
## main
1212

13-
* Fix segfault when Ruby coverage is enabled but template annotations are disabled.
13+
* Fix segfaults when Ruby coverage is enabled.
1414

15-
*George Holborn*
15+
*George Holborn*, *Joel Hawksley*
16+
17+
* Fix segfault when Ruby coverage is enabled and template annotations are enabled.
18+
19+
*Joel Hawksley*
1620

1721
* Add `protocol` parameter to `with_request_url` test helper to enable testing with HTTPS protocol.
1822

lib/view_component/template.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
require "coverage"
23

34
module ViewComponent
45
class Template
@@ -65,7 +66,7 @@ def compiled_source
6566
result = super
6667
# Strip the annotation line to maintain correct line numbers when coverage
6768
# is running (avoids segfault from negative lineno)
68-
result = result.sub(/\A[^\n]*\n/, "") if @strip_annotation_line
69+
result = result.partition(";").last if @strip_annotation_line
6970
result
7071
end
7172
end

0 commit comments

Comments
 (0)