Skip to content

Commit

Permalink
MetaTag: when encoding for XML special characters, handle non-string …
Browse files Browse the repository at this point in the history
…objects (#326)

Merge pull request 326
  • Loading branch information
parkr authored Oct 3, 2020
1 parent c8e7a43 commit df10ac8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/jekyll-feed/meta-tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ class MetaTag < Liquid::Tag

def render(context)
@context = context
attrs = attributes.map { |k, v| %(#{k}=#{v.encode(:xml => :attr)}) }.join(" ")
"<link #{attrs} />"
attrs = attributes.map do |k, v|
v = v.to_s unless v.respond_to?(:encode)
%(#{k}=#{v.encode(:xml => :attr)})
end
"<link #{attrs.join(" ")} />"
end

private
Expand Down
15 changes: 15 additions & 0 deletions spec/jekyll-feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@
end
end

context "with site.title set as a non-string value" do
class MySiteTitle
def to_s
"My Dynamic Site Title <&>"
end
alias_method :to_liquid, :to_s
end
let(:site_title) { MySiteTitle.new }
let(:overrides) { { "title" => site_title } }

it "ensures the site.title is the string representation of the object" do
expect(feed.title.content).to eql(site_title.to_s.encode(xml: :text))
end
end

context "with site.name set" do
let(:site_name) { "My Site Name" }
let(:overrides) { { "name" => site_name } }
Expand Down

0 comments on commit df10ac8

Please sign in to comment.