Skip to content

Commit facda81

Browse files
committed
Update events and tests.
- Update event code naming. Similar to JSON-LD error code style. Code name is just the condition detected, not the action that might be taken. - Relative reference events now at call sites. - No-value events now at call sites. - Remove some special-case event handlers. Not needed when events happen outside `_expandIri`. - **BREAKING**: Handle special non-normaitve spec edge case where value for `@id` can expand into null. Behavior changing to *not* output invalid JSON-LD. This can change triples in odd edge cases. - Add eventCodeLog test feature to test sequence of events codes. - Update tests.
1 parent 2b3240e commit facda81

File tree

5 files changed

+318
-261
lines changed

5 files changed

+318
-261
lines changed

CHANGELOG.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
# jsonld ChangeLog
22

3+
### Changed
4+
- Change EARL Assertor to Digital Bazaar, Inc.
5+
- Update eslint dependencies.
6+
- **BREAKING**: Handle spec edge case where value for `@id` can expand into
7+
null. Behavior is changing to *not* output invalid JSON-LD and *potentially*
8+
outputing an extra blank node. The input in question is something like
9+
`{"@id":"@RESERVED", ...}` where `@RESERVED` will expand into `null`. Rather
10+
than outputing invalid `{"@id": null, ...}`, the new behavior will drop
11+
`@id`. When going to RDF this can cause slightly different output.
12+
Specifically, a `{}` value may exist and create a blank node. Please file an
13+
issue if this behavior causes issues. It is expected to be better addressed
14+
in a future spec.
15+
- Related [issue](https://github.com/w3c/json-ld-api/issues/480).
16+
- Normative [toRdf test case](https://w3c.github.io/json-ld-api/tests/toRdf-manifest.html#te122)
17+
*that now fails*.
18+
- Non-normative [expand test case](https://w3c.github.io/json-ld-api/tests/expand-manifest.html#t0122)
19+
that now fails.
20+
321
### Added
422
- Support benchmarks in Karma tests.
523
- Support test environment in EARL output.
624
- Support benchmark output in EARL output.
725
- Benchmark comparison tool.
8-
- Event handler option `"eventHandler"` to allow custom handling of warnings and
9-
potentially other events in the future. Handles event replay for cached
26+
- Event handler option `"eventHandler"` to allow custom handling of warnings
27+
and potentially other events in the future. Handles event replay for cached
1028
contexts.
1129

12-
### Changed
13-
- Change EARL Assertor to Digital Bazaar, Inc.
14-
- Update eslint dependencies.
15-
1630
## 6.0.0 - 2022-06-06
1731

1832
### Changed

lib/context.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,25 @@ api.process = async ({
226226
'@context must be an absolute IRI.',
227227
'jsonld.SyntaxError', {code: 'invalid vocab mapping', context: ctx});
228228
} else {
229-
rval['@vocab'] = _expandIri(rval, value, {vocab: true, base: true},
229+
const vocab = _expandIri(rval, value, {vocab: true, base: true},
230230
undefined, undefined, options);
231+
if(!_isAbsoluteIri(vocab)) {
232+
if(options.eventHandler) {
233+
_handleEvent({
234+
event: {
235+
type: ['JsonLdEvent'],
236+
code: 'relative @vocab reference',
237+
level: 'warning',
238+
message: 'Relative @vocab reference found.',
239+
details: {
240+
vocab
241+
}
242+
},
243+
options
244+
});
245+
}
246+
}
247+
rval['@vocab'] = vocab;
231248
}
232249
defined.set('@vocab', true);
233250
}
@@ -497,10 +514,11 @@ api.createTermDefinition = ({
497514
_handleEvent({
498515
event: {
499516
type: ['JsonLdEvent'],
500-
code: 'invalid reserved term',
517+
code: 'reserved term',
501518
level: 'warning',
502519
message:
503-
'Terms beginning with "@" are reserved for future use and ignored.',
520+
'Terms beginning with "@" are ' +
521+
'reserved for future use and dropped.',
504522
details: {
505523
term
506524
}
@@ -592,11 +610,11 @@ api.createTermDefinition = ({
592610
_handleEvent({
593611
event: {
594612
type: ['JsonLdEvent'],
595-
code: 'invalid reserved value',
613+
code: 'reserved @reverse value',
596614
level: 'warning',
597615
message:
598-
'Values beginning with "@" are reserved for future use and' +
599-
' ignored.',
616+
'@reverse values beginning with "@" are ' +
617+
'reserved for future use and dropped.',
600618
details: {
601619
reverse
602620
}
@@ -641,11 +659,11 @@ api.createTermDefinition = ({
641659
_handleEvent({
642660
event: {
643661
type: ['JsonLdEvent'],
644-
code: 'invalid reserved value',
662+
code: 'reserved @id value',
645663
level: 'warning',
646664
message:
647-
'Values beginning with "@" are reserved for future use and' +
648-
' ignored.',
665+
'@id values beginning with "@" are ' +
666+
'reserved for future use and dropped.',
649667
details: {
650668
id
651669
}
@@ -1171,22 +1189,8 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
11711189
});
11721190
if(expandedResult !== undefined) {
11731191
value = expandedResult;
1174-
} else {
1175-
if(options.eventHandler) {
1176-
_handleEvent({
1177-
event: {
1178-
type: ['JsonLdEvent'],
1179-
code: 'relative IRI after expansion',
1180-
level: 'warning',
1181-
message: 'Expansion resulted in a relative IRI.',
1182-
details: {
1183-
value
1184-
}
1185-
},
1186-
options
1187-
});
1188-
}
11891192
}
1193+
// NOTE: relative reference events emitted at calling sites as needed
11901194
}
11911195

11921196
return value;

lib/events.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,23 @@ function _handle({event, handlers}) {
101101
}
102102

103103
const _notSafeEventCodes = new Set([
104-
'dropping empty object',
105-
'dropping free-floating scalar',
106-
'dropping object with only @id',
107-
'dropping object with only @list',
108-
'dropping object with only @value',
104+
'empty object',
105+
'free-floating scalar',
109106
'invalid @language value',
110-
'invalid property expansion',
111-
'invalid reserved term',
112-
'no value after expansion',
113-
'relative IRI after expansion'
107+
'invalid property',
108+
// NOTE: spec edge case
109+
'null @id value',
110+
'null @value value',
111+
'object with only @id',
112+
'object with only @language',
113+
'object with only @list',
114+
'object with only @value',
115+
'relative @id reference',
116+
'relative @type reference',
117+
'relative @vocab reference',
118+
'reserved @id value',
119+
'reserved @reverse value',
120+
'reserved term'
114121
]);
115122

116123
// safe handler that rejects unsafe warning conditions

0 commit comments

Comments
 (0)