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

question about unexpected "</script>" #40

Open
boly38 opened this issue Jun 28, 2018 · 0 comments
Open

question about unexpected "</script>" #40

boly38 opened this issue Jun 28, 2018 · 0 comments

Comments

@boly38
Copy link
Contributor

boly38 commented Jun 28, 2018

Hi
(you generator is very usefull, thanks)

I would like to know your opinion about the following use case:

As end user, I have html special char (like '<') into LD-JSON attributes

I write a little php script to represent the case:

<?php
require_once `vendor/autoload.php';

$context = \JsonLd\Context::create('news_article', [
    'headline' => 'Article headline',
    'description' => 'A terrible </script> here'
]);

echo $context;

echo "\n\nAn other way :\n\n";

$context = \JsonLd\Context::create('news_article', [
    'headline' => 'Article headline',
    'description' => htmlspecialchars('A terrible </script> here')
]);

echo $context;

Script output the following:

<script type="application/ld+json">{"@context":"http:\/\/schema.org","@type":"NewsArticle","headline":"Article headline","description":"A terrible <\/script> here"}</script>

An other way :

<script type="application/ld+json">{"@context":"http:\/\/schema.org","@type":"NewsArticle","headline":"Article headline","description":"A terrible &lt;\/script&gt; here"}</script>

You should notice that the first sample output an invalid HTML

I had created dedicated html page to show the escape issue:
https://gist.github.com/boly38/77164ae66055b596d75f62d789a4266a

I'm asking myself about where htmlspecialchars should be ?

  • on end-user side (like beside in the second sample)
  • or into the Torann library itself

what do you think?

As end-user, would be great that the library manages that point for me as, per specification, toString result is ready to embed html script.

thanks

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

No branches or pull requests

1 participant