diff --git a/activesupport/lib/active_support/core_ext/erb/util.rb b/activesupport/lib/active_support/core_ext/erb/util.rb index acb0c288c4ec7..3538445310d3d 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}|#{finish_re}/m) + 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 25a853c75bddf..aeabb5bf72044 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