Skip to content

Commit 44504d2

Browse files
authored
Merge pull request #625 from w3c/555-blind-spot-in-rdf-to-object-conversion
(closes #555) Fall back to default logic in `useNativeTypes` mode for RDF numbers which are not JSON numbers
2 parents f004001 + 10c39a9 commit 44504d2

7 files changed

+146
-8
lines changed

.gitignore

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
# Support JetBrains IDEs
2-
.idea
1+
# JetBrains IDEs
2+
.idea/
3+
4+
# pyenv version file
5+
.python-version

index.html

+34-4
Original file line numberDiff line numberDiff line change
@@ -5456,6 +5456,12 @@ <h3>Algorithm</h3>
54565456
<li>Initialize <var>converted value</var> to <var>value</var>.</li>
54575457
<li>Initialize <var>type</var> to <code>null</code></li>
54585458
<li>If <a data-link-for="JsonLdOptions">useNativeTypes</a> is <code>true</code>
5459+
<div class="candidate correction" id="change_5">
5460+
<span class="marker">Candidate Correction 5</span>
5461+
<p>This changes behavior when using native numbers where <a data-link-for="JsonLdOptions">useNativeTypes</a> is `true`.
5462+
For more information, refer to <a href="https://github.com/w3c/json-ld-api/issues/555">issue 555</a>.
5463+
</p>
5464+
</div>
54595465
<ol>
54605466
<li>If the
54615467
<a>datatype IRI</a>
@@ -5477,10 +5483,31 @@ <h3>Algorithm</h3>
54775483
<code>xsd:double</code> and its
54785484
<a>lexical form</a>
54795485
is a valid <code>xsd:integer</code> or <code>xsd:double</code>
5480-
according [[XMLSCHEMA11-2]], set <var>converted value</var>
5481-
to the result of converting the
5482-
<a>lexical form</a>
5483-
to a JSON <a>number</a>.</li>
5486+
according to [[XMLSCHEMA11-2]]<del cite="#change_5">,
5487+
set <var>converted value</var>
5488+
to the result of converting the
5489+
<a>lexical form</a>
5490+
to a JSON <a>number</a>.
5491+
</del><ins cite="#change_5">:
5492+
<ol>
5493+
<li>
5494+
Attempt to convert the <a>lexical form</a> to a <a>JSON number</a>
5495+
according to the
5496+
[[RFC8785]] <a data-cite="RFC8785#name-serialization-of-numbers">
5497+
JSON Serialization Scheme (JCS) 3.2.2.3 Serialization of Numbers
5498+
</a> procedure.
5499+
</li>
5500+
<li>
5501+
If the conversion is successful, set <var>converted value</var>
5502+
to its result.
5503+
</li>
5504+
<li>
5505+
Otherwise, set <var>type</var> to <a>datatype IRI</a>
5506+
of <var>value</var>.
5507+
</li>
5508+
</ol>
5509+
</ins>
5510+
</li>
54845511
</ol>
54855512
</li>
54865513
<li class="changed">Otherwise, if <a>processing mode</a> is not `json-ld-1.0`,
@@ -7056,6 +7083,9 @@ <h2>Change log</h2>
70567083
<a data-cite="JSON-LD11#embedding-json-ld-in-html-documents">Embedding JSON-LD in HTML Documents</a> [[JSON-LD11]]
70577084
for treating script elements as a single document,
70587085
as described in <a href="#change_4">Candidate Correction 4</a>.</li>
7086+
<li>2025-01-25: Correct some corner cases in transforming RDF Number Literals
7087+
to JSON numbers when <a data-link-for="JsonLdOptions">useNativeTypes</a> is `true`,
7088+
as described in <a href="#change_5">Candidate Correction 5</a>.</li>
70597089
<li>2024-01-25: Change processing step for <a>LoadDocumentCallback</a>
70607090
to not presume that the content type is for JSON,
70617091
as described in <a href="#change_6">Candidate Correction 6</a></li>

tests/expand-manifest.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ <h2>
941941
</dl>
942942
</dd>
943943
<dt id='t0041'>
944-
Test t0041 @language: null resets the default language
944+
Test t0041 @language: null
945945
</dt>
946946
<dd>
947947
<dl class='entry'>
@@ -950,7 +950,7 @@ <h2>
950950
<dt>Type</dt>
951951
<dd>jld:PositiveEvaluationTest, jld:ExpandTest</dd>
952952
<dt>Purpose</dt>
953-
<dd></dd>
953+
<dd>@language: null resets the default language</dd>
954954
<dt>input</dt>
955955
<dd>
956956
<a href='expand/0041-in.jsonld'>expand/0041-in.jsonld</a>

tests/fromRdf-manifest.html

+28
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,34 @@ <h2>
648648
</dd>
649649
</dl>
650650
</dd>
651+
<dt id='t0027'>
652+
Test t0027 use native types flag with values that cannot be serialized to JSON
653+
</dt>
654+
<dd>
655+
<dl class='entry'>
656+
<dt>id</dt>
657+
<dd>#t0027</dd>
658+
<dt>Type</dt>
659+
<dd>jld:PositiveEvaluationTest, jld:FromRDFTest</dd>
660+
<dt>Purpose</dt>
661+
<dd>useNativeTypes flag being true is disregarded for a value that cannot be serialized into a native JSON value.</dd>
662+
<dt>input</dt>
663+
<dd>
664+
<a href='fromRdf/0027-in.nq'>fromRdf/0027-in.nq</a>
665+
</dd>
666+
<dt>expect</dt>
667+
<dd>
668+
<a href='fromRdf/0027-out.jsonld'>fromRdf/0027-out.jsonld</a>
669+
</dd>
670+
<dt>Options</dt>
671+
<dd>
672+
<dl class='options'>
673+
<dt>useNativeTypes</dt>
674+
<dd>true</dd>
675+
</dl>
676+
</dd>
677+
</dl>
678+
</dd>
651679
<dt id='tdi01'>
652680
Test tdi01 rdfDirection: null with i18n literal with direction and no language
653681
</dt>

tests/fromRdf-manifest.jsonld

+10
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@
195195
"purpose": "Check list generation with rdf:first property and rdf:nil value.",
196196
"input": "fromRdf/0026-in.nq",
197197
"expect": "fromRdf/0026-out.jsonld"
198+
}, {
199+
"@id": "#t0027",
200+
"@type": ["jld:PositiveEvaluationTest", "jld:FromRDFTest"],
201+
"name": "use native types flag with values that cannot be serialized to JSON",
202+
"purpose": "useNativeTypes flag being true is disregarded for a value that cannot be serialized into a native JSON value.",
203+
"option": {
204+
"useNativeTypes": true
205+
},
206+
"input": "fromRdf/0027-in.nq",
207+
"expect": "fromRdf/0027-out.jsonld"
198208
}, {
199209
"@id": "#tdi01",
200210
"@type": [ "jld:PositiveEvaluationTest", "jld:FromRDFTest" ],

tests/fromRdf/0027-in.nq

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<http://example.com/boolean-native> <http://example.com/example> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .
2+
<http://example.com/boolean-native> <http://example.com/example> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
3+
4+
<http://example.com/boolean-object> <http://example.com/example> "True"^^<http://www.w3.org/2001/XMLSchema#boolean> .
5+
<http://example.com/boolean-object> <http://example.com/example> "False"^^<http://www.w3.org/2001/XMLSchema#boolean> .
6+
7+
<http://example.com/number-native> <http://example.com/example> "1"^^<http://www.w3.org/2001/XMLSchema#integer> .
8+
9+
<http://example.com/number-object> <http://example.com/example> "0.1e999999999999999"^^<http://www.w3.org/2001/XMLSchema#double> .
10+
<http://example.com/number-object> <http://example.com/example> "+INF"^^<http://www.w3.org/2001/XMLSchema#double> .
11+
<http://example.com/number-object> <http://example.com/example> "-INF"^^<http://www.w3.org/2001/XMLSchema#double> .

tests/fromRdf/0027-out.jsonld

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"@graph": [
3+
{
4+
"@id": "http://example.com/boolean-native",
5+
"http://example.com/example": [
6+
{
7+
"@type": "http://www.w3.org/2001/XMLSchema#boolean",
8+
"@value": true
9+
},
10+
{
11+
"@type": "http://www.w3.org/2001/XMLSchema#boolean",
12+
"@value": false
13+
}
14+
]
15+
},
16+
{
17+
"@id": "http://example.com/boolean-object",
18+
"http://example.com/example": [
19+
{
20+
"@type": "http://www.w3.org/2001/XMLSchema#boolean",
21+
"@value": "True"
22+
},
23+
{
24+
"@type": "http://www.w3.org/2001/XMLSchema#boolean",
25+
"@value": "False"
26+
}
27+
]
28+
},
29+
{
30+
"@id": "http://example.com/number-native",
31+
"http://example.com/example": [
32+
{
33+
"@type": "http://www.w3.org/2001/XMLSchema#integer",
34+
"@value": 1
35+
}
36+
]
37+
},
38+
{
39+
"@id": "http://example.com/number-object",
40+
"http://example.com/example": [
41+
{
42+
"@type": "http://www.w3.org/2001/XMLSchema#double",
43+
"@value": "0.1e999999999999999"
44+
},
45+
{
46+
"@type": "http://www.w3.org/2001/XMLSchema#double",
47+
"@value": "+INF"
48+
},
49+
{
50+
"@type": "http://www.w3.org/2001/XMLSchema#double",
51+
"@value": "-INF"
52+
}
53+
]
54+
}
55+
]
56+
}

0 commit comments

Comments
 (0)