Skip to content

Commit

Permalink
Merge pull request #4694 from pathawks/pr/xml_escape
Browse files Browse the repository at this point in the history
Merge pull request 4694
  • Loading branch information
jekyllbot committed Mar 22, 2016
2 parents f542d81 + aeecbd7 commit e873934
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/jekyll/filters.rb
Expand Up @@ -117,7 +117,7 @@ def date_to_rfc822(date)
#
# Returns the escaped String.
def xml_escape(input)
CGI.escapeHTML(input.to_s)
input.to_s.encode(:xml => :attr).gsub(/\A"|"\Z/, "")
end

# CGI escape a string for use in a URL. Replaces any special characters
Expand Down Expand Up @@ -308,7 +308,7 @@ def sample(input, num = 1)
#
# Returns a String representation of the object.
def inspect(input)
CGI.escapeHTML(input.inspect)
xml_escape(input.inspect)
end

private
Expand Down
4 changes: 4 additions & 0 deletions test/test_filters.rb
Expand Up @@ -394,6 +394,10 @@ def to_liquid
should "return a HTML-escaped string representation of an object" do
assert_equal "{&quot;&lt;a&gt;&quot;=&gt;1}", @filter.inspect({ "<a>" => 1 })
end

should "quote strings" do
assert_equal "&quot;string&quot;", @filter.inspect("string")
end
end

context "slugify filter" do
Expand Down

0 comments on commit e873934

Please sign in to comment.