Merge pull request #4694 from pathawks/pr/xml_escape

Merge pull request 4694
This commit is contained in:
jekyllbot 2016-03-22 15:09:57 -07:00
commit e873934d60
2 changed files with 6 additions and 2 deletions

View File

@ -117,7 +117,7 @@ module Jekyll
# #
# Returns the escaped String. # Returns the escaped String.
def xml_escape(input) def xml_escape(input)
CGI.escapeHTML(input.to_s) input.to_s.encode(:xml => :attr).gsub(/\A"|"\Z/, "")
end end
# CGI escape a string for use in a URL. Replaces any special characters # CGI escape a string for use in a URL. Replaces any special characters
@ -308,7 +308,7 @@ module Jekyll
# #
# Returns a String representation of the object. # Returns a String representation of the object.
def inspect(input) def inspect(input)
CGI.escapeHTML(input.inspect) xml_escape(input.inspect)
end end
private private

View File

@ -394,6 +394,10 @@ class TestFilters < JekyllUnitTest
should "return a HTML-escaped string representation of an object" do should "return a HTML-escaped string representation of an object" do
assert_equal "{&quot;&lt;a&gt;&quot;=&gt;1}", @filter.inspect({ "<a>" => 1 }) assert_equal "{&quot;&lt;a&gt;&quot;=&gt;1}", @filter.inspect({ "<a>" => 1 })
end end
should "quote strings" do
assert_equal "&quot;string&quot;", @filter.inspect("string")
end
end end
context "slugify filter" do context "slugify filter" do