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

MetaTag: when encoding for XML special characters, handle non-string objects #326

Merged
merged 1 commit into from
Oct 3, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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