Skip to content

Commit 7ad4d8f

Browse files
authored
Merge pull request rails#51304 from nikhilbhatt/fix_exception_raised_should_show_template_code
Fix exception raised from template should not show compiled code
2 parents 965b8c3 + 575c641 commit 7ad4d8f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

activesupport/lib/active_support/core_ext/erb/util.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ def self.tokenize(source) # :nodoc:
188188
else
189189
raise NotImplementedError, source.matched
190190
end
191+
192+
unless source.eos? || source.exist?(start_re) || source.exist?(finish_re)
193+
tokens << [:TEXT, source.rest]
194+
source.terminate
195+
end
191196
end
192197

193198
tokens

activesupport/test/core_ext/erb_util_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ def test_no_end
125125
], actual_tokens
126126
end
127127

128+
def test_text_end
129+
source = "<%= @post.title %> "
130+
actual_tokens = tokenize source
131+
assert_equal [[:OPEN, "<%="],
132+
[:CODE, " @post.title "],
133+
[:CLOSE, "%>"],
134+
[:TEXT, " "],
135+
], actual_tokens
136+
end
137+
128138
def tokenize(source)
129139
ERB::Util.tokenize source
130140
end

0 commit comments

Comments
 (0)