Skip to content

Commit

Permalink
Fix exception raised from template should not show compiled code
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilbhatt authored and byroot committed May 20, 2024
1 parent 965b8c3 commit 575c641
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions activesupport/lib/active_support/core_ext/erb/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ def self.tokenize(source) # :nodoc:
else
raise NotImplementedError, source.matched
end

unless source.eos? || source.exist?(start_re) || source.exist?(finish_re)
tokens << [:TEXT, source.rest]
source.terminate
end
end

tokens
Expand Down
10 changes: 10 additions & 0 deletions activesupport/test/core_ext/erb_util_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ def test_no_end
], actual_tokens
end

def test_text_end
source = "<%= @post.title %> "
actual_tokens = tokenize source
assert_equal [[:OPEN, "<%="],
[:CODE, " @post.title "],
[:CLOSE, "%>"],
[:TEXT, " "],
], actual_tokens
end

def tokenize(source)
ERB::Util.tokenize source
end
Expand Down

0 comments on commit 575c641

Please sign in to comment.