Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use String#encode for xml_escape filter instead of CGI.escapeHTML #4694

Merged
merged 2 commits into from Mar 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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/, "")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@envygeeks 👍

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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It passes 👍

end
end

context "slugify filter" do
Expand Down