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

Construct meta script by appending text node #1220

merged 1 commit into from Jun 20, 2018


None yet
2 participants
Copy link

westonruter commented Jun 20, 2018

I found on an environment that the meta was being output empty as:

<script type="application/ld+json"></script>

When looking at the logs I saw an error:

PHP Warning: DOMDocument::createElement(): unterminated entity reference d=mm&r=g","width":200,"height":200}} in …/amp/includes/class-amp-theme-support.php on line 984

When looking up the docs for DOMDocument::createElement() I found that while it does take a second parameter for the value, it apparently does not do escaping ( ):

The value of the element. By default, an empty element will be created. The value can also be set later with DOMElement::$nodeValue.

The value is used verbatim except that the < and > entity references will escaped. Note that & has to be manually escaped; otherwise it is regarded as starting an entity reference. Also " won't be escaped.

This is even noted in the second example. This was causing problems for a value like, specifically for the ampersands in the URL:

{"@context":"http:\/\/","publisher":{"@type":"Organization","name":"WCEU 2018 AMP Demos"},"@type":"WebPage","mainEntityOfPage":"https:\/\/\/","headline":"Home","datePublished":"2018-06-10T23:06:03+00:00","dateModified":"2018-06-10T23:06:03+00:00","author":{"@type":"Person","name":"Weston Ruter"},"image":{"@type":"ImageObject","url":"https:\/\/\/avatar\/bb16e7904f2f335b6c9f524cc533d2d2?s=200&d=mm&r=g","width":200,"height":200}}

The issue is fixed if the text node is explicitly created and appended to the script element.

@westonruter westonruter added this to the v1.0 milestone Jun 20, 2018

@westonruter westonruter requested a review from kienstra Jun 20, 2018

Copy link

kienstra left a comment


Hi @westonruter,
This looks good, and works as expected.

Like you mentioned, with this PR, image URLs that have ampersands appear as expected. Like:


I also saw that before this PR, an image URL with ampersands caused the data to not appear:


@westonruter westonruter merged commit ceb4aeb into develop Jun 20, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
continuous-integration/travis-ci/push The Travis CI build passed

@westonruter westonruter deleted the fix/schemaorg-meta branch Jun 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.