Skip to content

Commit 1df79be

Browse files
committed
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 24c8c3b commit 1df79be

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
Scheme (JCS) drafts. Changes in the JCS algorithm could cause changes in
2828
the `toRdf` output.
2929

30+
### Fixed
31+
- Expanding the value of a graph container which is already a graph object generates a recursive graph object.
32+
- Compacting multiple nodes in a graph container places them in `@included`.
33+
3034
## 1.7.0 - 2019-08-30
3135

3236
### Added

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$/,
@@ -119,11 +116,6 @@ const TEST_TYPES = {
119116
// mode
120117
/expand-manifest.jsonld#tp001$/,
121118
/expand-manifest.jsonld#tp002$/,
122-
// Don't double-expand an already expanded graph
123-
/expand-manifest.jsonld#t0081$/,
124-
// Double-expand an already expanded graph
125-
/expand-manifest.jsonld#t0095$/,
126-
/expand-manifest.jsonld#t0104$/,
127119
// indexed graph objects
128120
/expand-manifest.jsonld#t0102$/,
129121
// multiple graphs
@@ -418,13 +410,6 @@ const TEST_TYPES = {
418410
idRegex: [
419411
// blank node properties
420412
/toRdf-manifest.jsonld#t0118$/,
421-
// Don't double-expand an already expanded graph
422-
/toRdf-manifest.jsonld#te081$/,
423-
/toRdf-manifest.jsonld#te095$/,
424-
// Does not create a new graph object
425-
/toRdf-manifest.jsonld#te102$/,
426-
/toRdf-manifest.jsonld#te103$/,
427-
/toRdf-manifest.jsonld#te104$/,
428413
// well formed
429414
/toRdf-manifest.jsonld#twf01$/,
430415
/toRdf-manifest.jsonld#twf02$/,

0 commit comments

Comments
 (0)