diff --git a/lib/ejs.rb b/lib/ejs.rb index 686649a..7a87754 100644 --- a/lib/ejs.rb +++ b/lib/ejs.rb @@ -34,6 +34,7 @@ class << self def compile(source, options = {}) source = source.dup + remove_html_trailing_whitespaces!(source) js_escape!(source) replace_escape_tags!(source, options) replace_interpolation_tags!(source, options) @@ -57,6 +58,11 @@ def evaluate(template, locals = {}, options = {}) end protected + def remove_html_trailing_whitespaces!(source) + source.gsub!(/>[[:space:]]*$[[:space:]]*<') + source + end + def js_escape!(source) source.gsub!(JS_ESCAPE_PATTERN) { |match| '\\' + JS_ESCAPES[match] } source diff --git a/test/test_ejs.rb b/test/test_ejs.rb index ed760da..fba4dd1 100644 --- a/test/test_ejs.rb +++ b/test/test_ejs.rb @@ -122,6 +122,11 @@ class EJSEvaluationTest < Test::Unit::TestCase assert_equal "This\n\t\tis: that.\n\tok.\nend.", EJS.evaluate(template, :x => "that") end + test "newlines and whitespaces between html tags" do + template = "