Skip to content

Commit 706ec1b

Browse files
gkelloggdavidlehn
authored andcommitted
Don't swallow a graph object when expanding a graph container.
Wrap multiple objects in `@included` when compacting a graph container with multiple object values.
1 parent 8938513 commit 706ec1b

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## 2.0.0 - 2019-xx-xx
44

5+
### Fixed
6+
- Expanding the value of a graph container which is already a graph object
7+
generates a recursive graph object.
8+
- Compacting multiple nodes in a graph container places them in `@included`.
9+
510
### Changed
611
- Default processing mode changed to json-ld-1.1. Allows a 1.1 context to be
712
used after non-1.1 contexts.

lib/compact.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ api.compact = async ({
452452
_isSimpleGraph(expandedItem)) {
453453
// container includes @graph but not @id or @index and value is a
454454
// simple graph object add compact value
455+
// if compactedItem contains multiple values, it is wrapped in `@included`
456+
if(_isArray(compactedItem) && compactedItem.length > 1) {
457+
compactedItem = {'@included': compactedItem}
458+
}
455459
_addValue(
456460
nestResult, itemActiveProperty, compactedItem, {
457461
propertyIsArray:

lib/expand.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ async function _expandObject({
711711
!container.some(key => key === '@id' || key === '@index')) {
712712
// ensure expanded values are arrays
713713
expandedValue = _asArray(expandedValue)
714-
.map(v => _isGraph(v) ? v : {'@graph': _asArray(v)});
714+
.map(v => ({'@graph': _asArray(v)}));
715715
}
716716

717717
// FIXME: can this be merged with code above to simplify?

tests/test-common.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ const TEST_TYPES = {
4141
/compact-manifest.jsonld#t0105$/,
4242
// rel vocab
4343
/compact-manifest.jsonld#t0107$/,
44-
// @container: @graph with multiple objects
45-
/compact-manifest.jsonld#t0109$/,
46-
/compact-manifest.jsonld#t0110$/,
4744
// @type: @none
4845
/compact-manifest.jsonld#ttn01$/,
4946
/compact-manifest.jsonld#ttn02$/,
@@ -116,11 +113,6 @@ const TEST_TYPES = {
116113
specVersion: ['json-ld-1.0'],
117114
// FIXME
118115
idRegex: [
119-
// Don't double-expand an already expanded graph
120-
/expand-manifest.jsonld#t0081$/,
121-
// Double-expand an already expanded graph
122-
/expand-manifest.jsonld#t0095$/,
123-
/expand-manifest.jsonld#t0104$/,
124116
// indexed graph objects
125117
/expand-manifest.jsonld#t0102$/,
126118
// multiple graphs
@@ -424,13 +416,6 @@ const TEST_TYPES = {
424416
idRegex: [
425417
// blank node properties
426418
/toRdf-manifest.jsonld#t0118$/,
427-
// Don't double-expand an already expanded graph
428-
/toRdf-manifest.jsonld#te081$/,
429-
/toRdf-manifest.jsonld#te095$/,
430-
// Does not create a new graph object
431-
/toRdf-manifest.jsonld#te102$/,
432-
/toRdf-manifest.jsonld#te103$/,
433-
/toRdf-manifest.jsonld#te104$/,
434419
// terms beginning with ':'
435420
/toRdf-manifest.jsonld#te117$/,
436421
/toRdf-manifest.jsonld#te118$/,

0 commit comments

Comments
 (0)