From 575c6413bbc407497fb62aed1a4905301873dde0 Mon Sep 17 00:00:00 2001 From: nikhilbhatt Date: Tue, 12 Mar 2024 13:16:46 +0530 Subject: [PATCH] Fix exception raised from template should not show compiled code --- activesupport/lib/active_support/core_ext/erb/util.rb | 5 +++++ activesupport/test/core_ext/erb_util_test.rb | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/erb/util.rb b/activesupport/lib/active_support/core_ext/erb/util.rb index acb0c288c4..813762369b 100644 --- a/activesupport/lib/active_support/core_ext/erb/util.rb +++ b/activesupport/lib/active_support/core_ext/erb/util.rb @@ -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 diff --git a/activesupport/test/core_ext/erb_util_test.rb b/activesupport/test/core_ext/erb_util_test.rb index 25a853c75b..aeabb5bf72 100644 --- a/activesupport/test/core_ext/erb_util_test.rb +++ b/activesupport/test/core_ext/erb_util_test.rb @@ -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