properly escape quotes in titles and descriptions

This commit is contained in:
Ben Balter 2015-11-25 08:18:37 -05:00
parent eb99fb0a0a
commit 1af5f6c357
2 changed files with 10 additions and 3 deletions

View File

@ -18,7 +18,7 @@
{% endif %}
{% endif %}
{% if seo_title %}
{% assign seo_title = seo_title | markdownify | strip_html | strip_newlines | escape_once %}
{% assign seo_title = seo_title | replace:'"','"' | markdownify | strip_html | strip_newlines | replace:'"','"' | escape_once %}
{% endif %}
{% if page.description %}
@ -27,7 +27,7 @@
{% assign seo_description = site.description %}
{% endif %}
{% if seo_description %}
{% assign seo_description = seo_description | markdownify | strip_html | strip_newlines | escape_once %}
{% assign seo_description = seo_description | replace:'"','"' | markdownify | strip_html | strip_newlines | replace:'"','"' | escape_once %}
{% endif %}
{% if seo_title %}

View File

@ -35,7 +35,14 @@ describe Jekyll::SeoTag do
it "escapes titles" do
site = site({"title" => 'Jekyll & "Hyde"'})
context = context({ :site => site })
expect(subject.render(context)).to match(/<title>Jekyll &amp; “Hyde”<\/title>/)
expect(subject.render(context)).to match(/<title>Jekyll &amp; &quot;Hyde&quot;<\/title>/)
end
it "escapes descriptions" do
site = site({"description" => 'Jekyll & "Hyde"'})
context = context({ :site => site })
expected = /<meta name="description" content="Jekyll &amp; &quot;Hyde&quot;" \/>/
expect(subject.render(context)).to match(expected)
end
it "uses the page description" do