jekyll / jekyll-feed

:memo: A Jekyll plugin to generate an Atom (RSS-like) feed of your Jekyll posts
MIT License
827 stars 201 forks source link

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

Closed parkr closed 3 years ago

parkr commented 3 years ago

Fixes https://github.com/jekyll/jekyll-feed/issues/325.

The jekyll-github-metadata plugin, for example, sets site.title and site.name to Jekyll::GitHubMetadata::Value objects which respond to #to_s and #to_liquid, but NOT #encode. Therefore, we should cast to a string if #encode is not yet available.

The reason we cast to a string is because the previous code was "#{k}=#{v}", which was implicitly casting to a string for v.

ashmaroli commented 3 years ago

@parkr Do we really need to have that respond_to?(:encode) check? Can't we cast and proceed right away?

attributes.map { |k, v| "#{k}=#{v.to_s.encode(:xml => :attr)}" }.join(" ")
parkr commented 3 years ago

No worries at all 😄

@jekyllbot: merge +dev