Closed LeBenLeBen closed 7 years ago
It looks like the same problem occur if a text field include one or many "
. Those should be escaped as well then.
@LeBenLeBen Indeed, you're correct.
Your fix #47 introduces this line:
<div class="seo" data-seo-controller='<?php echo json_encode( $controller, JSON_HEX_APOS ); ?>'>
In order to cater for a much wider range of use-cases, I would suggest using this - copied from the PHP Manual entry for json_encode()
:
<div class="seo" data-seo-controller='<?php echo json_encode( $controller, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE ); ?>'>
According to the PHP Manual, this should cover quotes, apostrophes, ampersands, tags, but leave unicode characters alone.
I’ve updated the PR with all the flags. I’ve tested it on my installation and it works with both types of quotes now.
As you both @LeBenLeBen and @luxlogica have tried this successfully, I've now merged it.
In case your page title includes an apostrophe, like:
It triggers a JavaScript error:
while jQuery try to parse the JSON in the following function:
This is caused by apostrophes not being encoded in the JSON embedded in the DOM.