Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Fix issue #15 #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ejs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def js_unescape!(source)

def replace_escape_tags!(source, options)
source.gsub!(options[:escape_pattern] || escape_pattern) do
"',(''+#{js_unescape!($1)})#{escape_function},'"
"',(''+(#{js_unescape!($1)}))#{escape_function},'"
end
end

Expand Down
26 changes: 26 additions & 0 deletions test/test_ejs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,32 @@ class EJSEvaluationTest < Test::Unit::TestCase
assert_equal "&#x27;Foo Bar&#x27;", EJS.evaluate(template, { :foobar => "'Foo Bar'" })
end

test "escaping with conditions" do
params = { :foobar => "<b>Foo Bar</b>" }
safe_string = "&lt;b&gt;Foo Bar&lt;&#x2F;b&gt;"

template = "<%- true || foobar %>"
assert_equal "true", EJS.evaluate(template, params)

template = "<%- null || foobar %>"
assert_equal safe_string, EJS.evaluate(template, params)

template = "<%- false || foobar %>"
assert_equal safe_string, EJS.evaluate(template, params)

template = "<%- foobar || 'Foo & Bar' %>"
assert_equal safe_string, EJS.evaluate(template, params)

template = "<%- true ? foobar : 'foobar' %>"
assert_equal safe_string, EJS.evaluate(template, params)

template = "<%- false ? foobar : 'Foo & Bar' %>"
assert_equal "Foo &amp; Bar", EJS.evaluate(template, params)

template = "<%- true ? (false || 'Foo & Bar') : 'Foo' %>"
assert_equal "Foo &amp; Bar", EJS.evaluate(template, params)
end

test "braced escaping" do
template = "{{- foobar }}"
assert_equal "&lt;b&gt;Foo Bar&lt;&#x2F;b&gt;", EJS.evaluate(template, { :foobar => "<b>Foo Bar</b>" }, BRACE_SYNTAX)
Expand Down