SchemaMetatagManager::encodeJsonld Should Allow for HTML

Created on 31 July 2018, over 6 years ago
Updated 8 December 2023, about 1 year ago

Problem/Motivation

SchemaMetatagManager::encodeJsonld uses json_encode() with a number of options that garble any HTML contained in $items. This is problematic in the case of job postings because Google requires the 'description' property to be valid HTML: https://developers.google.com/search/docs/data-types/job-posting#JobPost....

Specifically, the json_encode() options are as follows:

  • JSON_HEX_TAG
  • JSON_HEX_APOS
  • JSON_HEX_AMP
  • JSON_HEX_QUOT

Proposed resolution

Remove the options in question:

  public static function encodeJsonld(array $items) {
    // If some group has been found, render the JSON LD,
    // otherwise return nothing.
    if (!empty($items)) {
-     return json_encode($items, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE);
+     return json_encode($items, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    }
    else {
      return '';
    }
  }

Remaining tasks

Community/maintainer feedback.

User interface changes

None.

API changes

None.

Data model changes

None.

✨ Feature request
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Chris Burge

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024