Skip to content

Commit

Permalink
Fix escape_once double-escaping hex-encoded entities
Browse files Browse the repository at this point in the history
(This is a manual merge of #9102)
  • Loading branch information
johndouthat authored and chancancode committed Jul 2, 2014
1 parent 9eb15ed commit 41de23e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions actionview/test/template/erb_util_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def test_rest_in_ascii

def test_html_escape_once
assert_equal '1 &lt;&gt;&amp;&quot;&#39; 2 &amp; 3', html_escape_once('1 <>&"\' 2 &amp; 3')
assert_equal " &#X27; &#x27; &#x03BB; &#X03bb; &quot; &#39; &lt; &gt; ", html_escape_once(" &#X27; &#x27; &#x03BB; &#X03bb; \" ' < > ")
end

def test_html_escape_once_returns_unsafe_strings_when_passed_unsafe_strings
Expand Down
1 change: 1 addition & 0 deletions actionview/test/template/tag_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def test_cdata_section_splitted

def test_escape_once
assert_equal '1 &lt; 2 &amp; 3', escape_once('1 < 2 &amp; 3')
assert_equal " &#X27; &#x27; &#x03BB; &#X03bb; &quot; &#39; &lt; &gt; ", escape_once(" &#X27; &#x27; &#x03BB; &#X03bb; \" ' < > ")
end

def test_tag_honors_html_safe_for_param_values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Util
HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;', "'" => '&#39;' }
JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003e', '<' => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
HTML_ESCAPE_REGEXP = /[&"'><]/
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+)|(#[xX][\dA-Fa-f]{1,4}));)/
JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/u

# A utility method for escaping HTML tag characters.
Expand Down

0 comments on commit 41de23e

Please sign in to comment.