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

Do not escape characters in formatted date #111

Merged
merged 1 commit into from
Jun 20, 2019
Merged

Do not escape characters in formatted date #111

merged 1 commit into from
Jun 20, 2019

Conversation

vincevriend
Copy link
Contributor

Remove quotes in the template so that the '+' character will no longer needlessly be escaped as '\x2b'.
Because the + character is part of the datetime it will render an invalid date in the JSON Linked Data, which may hurt SEO.

Without this fix:

<script type="application/ld+json">
...
"dateModified": "2014-09-28T00:00:00\x2b00:00",
...
</script>

With this fix:

<script type="application/ld+json">
...
"dateModified": "2014-09-28T00:00:00+00:00",
...
</script>

Without the quotes in the template the '+' character will no longer
needlessly be escaped as '\x2b'
@alanorth
Copy link
Owner

You're absolutely right. Even Google's Structured Data Testing Tool notices that this is malformed JSON-LD in one of my latest blog posts:

Screenshot_2019-06-20 Structured Data Testing Tool-fs8

Thank you for this, @TommySprat.

@alanorth alanorth merged commit 63e36db into alanorth:master Jun 20, 2019
alanorth added a commit that referenced this pull request Jun 20, 2019
Special characters in the unquoted date string get escaped and may
hurt SEO as this causes malformed JSON-lD. Fix contributed by user
@TommySprat.

See: #111
alanorth added a commit that referenced this pull request Mar 19, 2020
I don't understand it, but quoting these values causes Hugo to use
escape codes for non-ASCII (?) characters. For example:

  "description": "A thriving oasis in Jordan\x27s desert is at risk of disappearing."

Google's Search Console shows the following error:

    Unparsable structured data > Bad escape sequence in string

We had a similar issue with dates that was fixed in #111 and the
solution is the same here.
alanorth added a commit that referenced this pull request Mar 22, 2020
This is similar to other encoding issues we have fixed lately where
we need to make sure Hugo (or Golang's HTML template library) does
not escape our non-ASCII content.

For example, this is how our datetimes end up currently:

    <p class="blog-post-meta"><time datetime="2020-01-16T09:23:20&#43;02:00">Thu Jan 16, 2020</time> by Alan Orth

After printing them with `printf` and filtering them with the Hugo
built-in function `safeHTMLAttr` they look like this:

    <p class="blog-post-meta"><time datetime="2020-01-16T09:23:20+02:00">Thu Jan 16, 2020</time> by Alan Orth

See: https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/opengraph.html
See: #111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants