Skip to content

Commit d16d553

Browse files
committed
Remove HTML comment usage in data blocks
JSON-LD script elments MUST only contain valid JSON. HTML entity-based character encoding is used to avoid accidental script tag parsing problems--as described in the note in Restrictions for contents of <script> elements: https://www.w3.org/TR/html52/semantics-scripting.html#restrictions-for-contents-of-script-elements
1 parent 44fc855 commit d16d553

File tree

1 file changed

+24
-51
lines changed

1 file changed

+24
-51
lines changed

index.html

Lines changed: 24 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8677,46 +8677,29 @@ <h3>Graph Containers</h3>
86778677
<a data-cite="HTML52/infrastructure.html#dynamic-changes-to-base-urls">Dynamic changes to base URLs</a>.</p>
86788678

86798679
<section><h3>Restrictions for contents of JSON-LD <code>script</code> elements</h3>
8680-
<p class="issue atrisk">As HTML entities and comments are not allowable in
8681-
JSON, the use of comments, escapes,
8682-
and <a data-cite="HTML5/syntax.html#character-references">HTML Character references</a>
8683-
is subject to further discussion in the Working Group.</p>
8680+
<p class="issue atrisk">This section adds additional requirements for escaping
8681+
certain JSON values when embedding that JSON within HTML. This approach
8682+
is consequently subject to further discussion in the Working Group.</p>
86848683

86858684
<p>Depending on how the HTML document is served, certain strings may need
8686-
to be escaped. In particular, the content MAY be enclosed
8687-
in the HTML <em>comment-open</em> (<code>&lt;!--</code>) and <em>comment-close</em> (<code>--&gt;</code>) text sequences.</p>
8688-
<p>As described in HTML <a data-cite="HTML52/semantics-scripting.html#restrictions-for-contents-of-script-elements">Restrictions for contents of <code>&lt;script&gt;</code> elements</a>
8689-
the <a data-cite="DOM#dom-node-textcontent">textContent</a> of a script element may include balanced comments
8690-
and other text which complicate extracting the JSON-LD content from a <a data-cite="HTML52/semantics-scripting.html#data-block">data blocks</a>.
8691-
JSON-LD places further restrictions on the contents of
8692-
<a data-cite="HTML52/semantics-scripting.html#the-script-element">script elements</a> containing JSON-LD.</p>
8693-
<p>A JSON-LD script element MAY begin with an optional <em>comment-open</em> surrounded by any amount of <a data-cite="HTML52/infrastructure.html#space-characters">space characters</a>,
8694-
followed by valid JSON and ending with an optional <em>comment-close</em> surrounded by any amount of <a data-cite="HTML52/infrastructure.html#space-characters">space characters</a>.
8695-
Any content within the JSON content which can be confused with a <em>comment-open</em>, <em>script-open</em>,
8696-
<em>comment-close</em>, or <em>script-close</em> MUST be escaped using a REVERSE SOLIDUS (<code>\</code>) character
8697-
as follows:</p>
8698-
<ul>
8699-
<li><code>&lt;!--</code><code>&lt;\!--</code></li>
8700-
<li><code>&lt;script</code><code>&lt;\script</code></li>
8701-
<li><code>--&gt;</code><code>--\&gt;</code></li>
8702-
<li><code>&lt;/script</code><code>&lt;\/script</code></li>
8703-
</ul>
8704-
<p>Additionally, content of a script element MAY be escaped using <a data-cite="HTML5/syntax.html#character-references">HTML Character references</a>, such as the following:</p>
8685+
to be escaped to prevent disrupting the HTML parsing algorithm.</p>
8686+
8687+
<p>Due to the HTML <a data-cite="HTML52/semantics-scripting.html#restrictions-for-contents-of-script-elements">Restrictions for contents of <code>&lt;script&gt;</code> elements</a>
8688+
additional encoding restrictions are placed on JSON-LD data contained in
8689+
<a data-cite="HTML52/semantics-scripting.html#the-script-element">script elements</a>.</p>
8690+
<p>A JSON-LD script element MUST contain only valid JSON.
8691+
Any strings within the JSON content which contains text which can be confused with a <em>comment-open</em>, <em>script-open</em>,
8692+
<em>comment-close</em>, or <em>script-close</em> MUST be escaped using <a data-cite="HTML5/syntax.html#character-references">HTML Character references</a>, such as the following:</p>
87058693
<ul>
87068694
<li><code>&amp;amp;</code> → &amp; (<a href="/wiki/Ampersand" title="Ampersand">ampersand</a>, U+0026)</li>
87078695
<li><code>&amp;lt;</code> → &lt; (less-than sign, U+003C)</li>
87088696
<li><code>&amp;gt;</code> → &gt; (greater-than sign, U+003E)</li>
87098697
<li><code>&amp;quot;</code> → " (quotation mark, U+0022)</li>
87108698
<li><code>&amp;apos;</code> → ' (apostrophe, U+0027)</li>
87118699
</ul>
8712-
<p>JSON-LD Processors MUST remove surrounding <em>comment-open</em> and <em>comment-close</em>
8713-
sequences, unescape any escaped <em>comment-open</em>, <em>comment-close</em>,
8714-
<em>script-open</em>, and <em>script-close</em> sequences,
8715-
and turn <a data-cite="HTML5/syntax.html#character-references">HTML Character references</a> into the corresponding Unicode.
8716-
</p>
87178700

87188701
<aside class="example ds-selector-tabs"
8719-
title="Embedding JSON-LD in HTML with comments">
8702+
title="Embedding JSON-LD containing HTML in HTML">
87208703
<div class="selectors">
87218704
<button class="selected" data-selects="original">Original</button>
87228705
<button data-selects="expanded">Expanded</button>
@@ -8727,15 +8710,12 @@ <h3>Graph Containers</h3>
87278710
data-content-type="text/html">
87288711
<!--
87298712
<script type="application/ld+json">
8730-
< ! - -
87318713
{
8732-
"@context": "https://json-ld.org/contexts/person.jsonld",
8733-
"@id": "http://dbpedia.org/resource/John_Lennon",
8734-
"name": "John Lennon",
8735-
"born": "1940-10-09",
8736-
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
8714+
"@context": "http://schema.org/",
8715+
"@type": "WebPageElement",
8716+
"name": "Encoding Issues",
8717+
"description": "Issues list such as unescaped &lt;/script&gt; or --&gt;"
87378718
}
8738-
- - >
87398719
</script>
87408720
-->
87418721
</pre>
@@ -8744,13 +8724,10 @@ <h3>Graph Containers</h3>
87448724
data-result-for="Embedding JSON-LD in HTML with comments-original">
87458725
<!--
87468726
[{
8747-
"@id": "http://dbpedia.org/resource/John_Lennon",
8748-
"http://xmlns.com/foaf/0.1/name": [{"@value": "John Lennon"}],
8749-
"http://schema.org/birthDate": [
8750-
{"@value": "1940-10-09", "@type": "http://www.w3.org/2001/XMLSchema#date"}
8751-
],
8752-
"http://schema.org/spouse": [
8753-
{"@id": "http://dbpedia.org/resource/Cynthia_Lennon"}
8727+
"@type": "http://schema.org/WebPageElement",
8728+
"http://schema.org/name": [{"@value": "Encoding Issues"}],
8729+
"http://schema.org/description": [
8730+
{"@value": "Issues list such as unescaped &lt;/script&gt; or --&gt;"}
87548731
]
87558732
}]
87568733
-->
@@ -8760,9 +8737,8 @@ <h3>Graph Containers</h3>
87608737
data-to-rdf>
87618738
<thead><tr><th>Subject</th><th>Property</th><th>Value</th><th>Value Type</th></tr></thead>
87628739
<tbody>
8763-
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>foaf:name</td><td>John Lennon</td><td>&nbsp;</td></tr>
8764-
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>schema:birthDate</td><td>1940-10-09</td><td>xsd:date</td></tr>
8765-
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>schema:spouse</td><td>http://dbpedia.org/resource/Cynthia_Lennon</td><td>&nbsp;</td></tr>
8740+
<tr><td>_:b0</td><td>schema:name</td><td>Encoding Issues</td><td>&nbsp;</td></tr>
8741+
<tr><td>_:b0</td><td>schema:description</td><td>Issues list such as unescaped &amp;lt;/script&amp;gt; or --&amp;gt;</td><td>&nbsp;</td></tr>
87668742
</tbody>
87678743
</table>
87688744
<pre class="turtle"
@@ -8771,13 +8747,10 @@ <h3>Graph Containers</h3>
87718747
data-result-for="Embedding JSON-LD in HTML with comments-expanded"
87728748
data-to-rdf>
87738749
<!--
8774-
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
87758750
@prefix schema: <http://schema.org/> .
8776-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
87778751
8778-
<http://dbpedia.org/resource/John_Lennon> foaf:name "John Lennon";
8779-
schema:birthDate "1940-10-09"^^xsd:date;
8780-
schema:spouse <http://dbpedia.org/resource/Cynthia_Lennon> .
8752+
<> schema:name "Encoding Issues";
8753+
schema:description "Issues list such as unescaped &lt;/script&gt; or --&gt;" .
87818754
-->
87828755
</pre>
87838756
</aside>

0 commit comments

Comments
 (0)