Skip to content

Commit

Permalink
correctly escape titles subtitles and excerpts in all contexts; fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
daattali committed Oct 10, 2021
1 parent 24e182b commit 505305e
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased version

- Added `post_search` config setting that creates a Search button in the navbar (older websites need to set `post_search: true` to enable this feature) (#770)
- Fixed page titles, subtitles, and excerpts rendering correctly when there are special characeters in them (#856)
- Slightly reworked margins and position for avatar image to resolve an alignment issue on Safari.
- Changed the width at which the navbar collapses to a higher threshold because most modern non-mobile browsers are >1000px
- Fixed bug where navbar secondary level dropdown items didn't inherit the same colour as the primary navbar links
Expand Down
12 changes: 6 additions & 6 deletions _includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
<div class="row">
<div class="col-xl-8 offset-xl-2 col-lg-10 offset-lg-1">
<div class="{{ include.type }}-heading">
<h1>{% if page.title %}{{ page.title }}{% else %}<br/>{% endif %}</h1>
<h1>{% if page.title %}{{ page.title | strip_html }}{% else %}<br/>{% endif %}</h1>
{% if page.subtitle %}
{% if include.type == "page" %}
<hr class="small">
<span class="{{ include.type }}-subheading">{{ page.subtitle }}</span>
<span class="{{ include.type }}-subheading">{{ page.subtitle | strip_html }}</span>
{% else %}
<h2 class="{{ include.type }}-subheading">{{ page.subtitle }}</h2>
<h2 class="{{ include.type }}-subheading">{{ page.subtitle | strip_html }}</h2>
{% endif %}
{% endif %}

Expand Down Expand Up @@ -61,13 +61,13 @@ <h2 class="{{ include.type }}-subheading">{{ page.subtitle }}</h2>
<div class="row">
<div class="col-xl-8 offset-xl-2 col-lg-10 offset-lg-1">
<div class="{{ include.type }}-heading">
<h1>{% if page.title %}{{ page.title }}{% else %}<br/>{% endif %}</h1>
<h1>{% if page.title %}{{ page.title | strip_html }}{% else %}<br/>{% endif %}</h1>
{% if page.subtitle %}
{% if include.type == "page" %}
<hr class="small">
<span class="{{ include.type }}-subheading">{{ page.subtitle }}</span>
<span class="{{ include.type }}-subheading">{{ page.subtitle | strip_html }}</span>
{% else %}
<h2 class="{{ include.type }}-subheading">{{ page.subtitle }}</h2>
<h2 class="{{ include.type }}-subheading">{{ page.subtitle | strip_html }}</h2>
{% endif %}
{% endif %}

Expand Down
4 changes: 2 additions & 2 deletions _includes/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
var searchjson = '[ \
{% for post in site.posts %} \
{ \
"title" : "{% if post.title != "" %}{{ post.title | escape }}{% else %}{{ post.excerpt | strip_html | escape | strip }}{%endif%}", \
"title" : "{% if post.title != "" %}{{ post.title | strip_html | escape }}{% else %}{{ post.excerpt | strip_html | escape | strip }}{%endif%}", \
"category" : "{{ post.tags | join: \', \' }}", \
"url" : "{{ site.baseurl }}{{ post.url }}", \
"date" : "{{ post.date | date: "%B %e, %Y" | default: "January 1, 1970" }}" \
}, \
{% endfor %} \
{% for page in site.html_pages %}{% if page.title != "{title}" and page.title != "404 - Page not found" %} \
{ \
"title" : "{% if page.title != "" %}{{ page.title | escape }}{% else %}{{ page.excerpt | strip_html | escape | strip }}{% endif %}", \
"title" : "{% if page.title != "" %}{{ page.title | strip_html | escape }}{% else %}{{ page.excerpt | strip_html | escape | strip }}{% endif %}", \
"category" : "{% if page.tags %}{{ page.tags | join: \', \' }}{% else %}page{% endif %}", \
"url" : "{{ site.baseurl }}{{ page.url }}", \
"date" : "{{ page.date | date: '%B %e, %Y' | default: "January 1, 1970" }}" \
Expand Down
2 changes: 1 addition & 1 deletion _includes/social-share.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<span class="sr-only">Share: </span>

{% if site.share-links-active.twitter %}
<a href="https://twitter.com/intent/tweet?text={{ page.title | url_encode }}&url={{ page.url | absolute_url | url_encode }}"
<a href="https://twitter.com/intent/tweet?text={{ page.title | strip_html | url_encode }}&url={{ page.url | absolute_url | url_encode }}"
class="btn btn-social-icon btn-twitter" title="Share on Twitter">
<span class="fab fa-fw fa-twitter" aria-hidden="true"></span>
<span class="sr-only">Twitter</span>
Expand Down
6 changes: 3 additions & 3 deletions _layouts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
{% endif %}

<a href="{{ post.url | absolute_url }}">
<h2 class="post-title">{{ post.title }}</h2>
<h2 class="post-title">{{ post.title | strip_html }}</h2>

{% if post.subtitle %}
<h3 class="post-subtitle">
{{ post.subtitle }}
{{ post.subtitle | strip_html }}
</h3>
{% endif %}
</a>
Expand Down Expand Up @@ -68,7 +68,7 @@ <h3 class="post-subtitle">

<div class="post-entry">
{% assign excerpt_length = site.excerpt_length | default: 50 %}
{{ post.excerpt | strip_html | xml_escape | truncatewords: excerpt_length }}
{{ post.excerpt | strip_html | truncatewords: excerpt_length }}
{% assign excerpt_word_count = post.excerpt | number_of_words %}
{% if post.content != post.excerpt or excerpt_word_count > excerpt_length %}
<a href="{{ post.url | absolute_url }}" class="post-read-more">[Read&nbsp;More]</a>
Expand Down
4 changes: 2 additions & 2 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
<ul class="pagination blog-pager">
{% if page.previous.url %}
<li class="page-item previous">
<a class="page-link" href="{{ page.previous.url | relative_url }}" data-toggle="tooltip" data-placement="top" title="{{page.previous.title}}">&larr; Previous Post</a>
<a class="page-link" href="{{ page.previous.url | relative_url }}" data-toggle="tooltip" data-placement="top" title="{{page.previous.title | strip_html | xml_escape}}">&larr; Previous Post</a>
</li>
{% endif %}
{% if page.next.url %}
<li class="page-item next">
<a class="page-link" href="{{ page.next.url | relative_url }}" data-toggle="tooltip" data-placement="top" title="{{page.next.title}}">Next Post &rarr;</a>
<a class="page-link" href="{{ page.next.url | relative_url }}" data-toggle="tooltip" data-placement="top" title="{{page.next.title | strip_html | xml_escape}}">Next Post &rarr;</a>
</li>
{% endif %}
</ul>
Expand Down
6 changes: 3 additions & 3 deletions _posts/2020-02-26-flake-it-till-you-make-it.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
layout: post
title: Flake it till you make it
subtitle: Excerpt from Soulshaping by Jeff Brown
title: "Flake it & un + he`<i>AA</i>`y <i>BB</i> : per g > % cent ' till y\"ou make it"
subtitle: "Excerpt from \"Soul<i>ITTT</i>shaping by Jeff Brown"
cover-img: /assets/img/path.jpg
thumbnail-img: /assets/img/thumb.png
share-img: /assets/img/path.jpg
tags: [books, test]
---

Under what circumstances should we step off a path? When is it essential that we finish what we start? If I bought a bag of peanuts and had an allergic reaction, no one would fault me if I threw it out. If I ended a relationship with a woman who hit me, no one would say that I had a commitment problem. But if I walk away from a seemingly secure route because my soul has other ideas, I am a flake?
Under what & f < d > g + g : `<strong>g</strong>`y <strong>sg</strong> e % t ' c " circusmstances should we step off a path? When is it essential that we finish what we start? If I bought a bag of peanuts and had an allergic reaction, no one would fault me if I threw it out. If I ended a relationship with a woman who hit me, no one would say that I had a commitment problem. But if I walk away from a seemingly secure route because my soul has other ideas, I am a flake?

The truth is that no one else can definitively know the path we are here to walk. It’s tempting to listen—many of us long for the omnipotent other—but unless they are genuine psychic intuitives, they can’t know. All others can know is their own truth, and if they’ve actually done the work to excavate it, they will have the good sense to know that they cannot genuinely know anyone else’s. Only soul knows the path it is here to walk. Since you are the only one living in your temple, only you can know its scriptures and interpretive structure.

Expand Down
4 changes: 2 additions & 2 deletions _posts/2020-02-28-test-markdown.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: post
title: Sample blog post
subtitle: Each post also has a subtitle
title: Sample blog <i>fds</i>post
subtitle: Each post al<i>ITAL</i>so has a subtitle
gh-repo: daattali/beautiful-jekyll
gh-badge: [star, fork, follow]
tags: [test]
Expand Down
4 changes: 2 additions & 2 deletions feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ layout: null
{% assign excerpt_length = site.excerpt_length | default: 50 %}
{% for post in site.posts limit:20 %}
<item>
<title>{{ post.title | xml_escape }}</title>
<title>{{ post.title | strip_html | xml_escape }}</title>
<description>
{% if post.subtitle %}{{ post.subtitle | xml_escape }} - {% endif %}
{% if post.subtitle %}{{ post.subtitle | strip_html | xml_escape }} - {% endif %}
{{ post.content | strip_html | xml_escape | truncatewords: excerpt_length }}
</description>
<pubDate>{{ post.date | date: "%a, %d %b %Y %H:%M:%S %z" }}</pubDate>
Expand Down
2 changes: 1 addition & 1 deletion tags.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2 id="{{- tag -}}" class="linked-section">
<div class="post-list">
{%- for post in site.tags[tag] -%}
<div class="tag-entry">
<a href="{{ post.url | relative_url }}">{{- post.title -}}</a>
<a href="{{ post.url | relative_url }}">{{- post.title | strip_html -}}</a>
<div class="entry-date">
<time datetime="{{- post.date | date_to_xmlschema -}}">{{- post.date | date: date_format -}}</time>
</div>
Expand Down

0 comments on commit 505305e

Please sign in to comment.