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 committed Mar 21, 2024
1 parent 30e3738 commit e60ea9b
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
Expand Up @@ -188,6 +188,11 @@ def self.tokenize(source) # :nodoc:
else
raise NotImplementedError, source.matched
end

unless source.eos? || source.exist?(/#{start_re}|#{finish_re}/m)
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
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 e60ea9b

Please sign in to comment.